The Gateway to Computer Science Excellence
+2 votes
Consider the following C code:
include <stdio.h>
int fun()
static int num=25;
return num--;
int main()
for(fun( ); fun();fun())
printf("%d", fun( ));
return O;
The sum of the values printed by the above program will be


in Programming by Loyal (5.3k points)
edited by | 179 views

yes 100     how to solve these types of questions

first time when for loop is executed it become

1. for(fun=25;fun()//here decrement will take place so now value is 24;fun())

   printf ("%d",fun()   //here decrement will take place so now value is 23)

2. now condition check so value become 22

3 now again for loop for(fun=22;fun()  //here decrement will take place so now value is 21; fun())

 printf ("%d",fun()   //here decrement will take place so now value is 20)


nd so on

1 Answer

+1 vote
It won't do anything , it will have compilation error.

Used : instead of ;

If we consider it without errors , equivalent while loop can be written as :-

fun(); //initialization

while(fun()//termination condition when fun() gets 0) {




which will print :-

by Loyal (5.8k points)
But we are performing 4 fun() in each the sequence should be 22,18,14,10,6,2, right?
4 . How? initialization happens only once in for loop
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,279 answers
104,840 users