The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
148 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 by Active (4.2k points)
edited by | 148 views
0
100?
0

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
by Loyal (5.6k points)
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

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,376 questions
55,839 answers
192,571 comments
91,393 users