search
Log In
2 votes
281 views
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
edited by
281 views
1
100?
1

yes 100     how to solve these types of questions

0
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) {

print("%d",fun());

fun();

}

which will print :-

2320171411852
0
But we are performing 4 fun() in each iteration..so the sequence should be 22,18,14,10,6,2, right?
0
4 . How? initialization happens only once in for loop

Related questions

0 votes
1 answer
1
147 views
Please explained detialed execution of this code, I am not getting how int stored in char, like we can interchange using ASCII but still cant store right?
asked Jan 10, 2019 in Programming Markzuck 147 views
1 vote
0 answers
3
109 views
Which one of the choices given below would be printed when the following program is executed? My answer is - mech, g, mech. Correct answer is - mech, g, civil I want to know why the last print statement prints civil.
asked Jan 22, 2018 in Programming Akash Mishra 109 views
2 votes
0 answers
4
185 views
Consider the following program: The value printed by the above program is: 1. 20 2. 30 3. 40 4. 50 I think it will be undefined behaviour because of: arr[count++] = incr(); But I am not sure. need to confirm.
asked Jan 15, 2018 in Programming Rishabh Gupta 2 185 views
...