void main()
{
static int i = 5;
if(--i)
{
main();
printf("%d
",i);
}
}

what would be output of the above program and justify your
answer?

}

Answer Posted / samrat

Ans: 0 0 0 0

The first thing you have to remember is that static
variables are initialized only once. The second thing is
that static variables have a life time scope and they retain
their value between function calls.

"i" is first initialized to 5. in the if condition the value
of i is changed to 4. main() is called again and the value
of i is changed to 3 in the if condition and main is called
again. Now the value of i is changed to 2 and main is called
again. Now the value of i is changed to 1 and main is called
again. After this the value of i is changed to "0" and the
block is excited.

As the value of i is now "0", it is printed 4 times for each
of the calls for main(). So the ans will be
0
0
0
0

Thanks,
Samrat

Is This Answer Correct ?    67 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What will be the outcome of the following conditional statement if the value of variable s is 10?

731


What is scanf () in c?

642


Explain the difference between malloc() and calloc() in c?

555


How will you declare an array of three function pointers where each function receives two ints and returns a float?

747


What is c language & why it is used?

554






What are the 5 elements of structure?

542


What is array in c with example?

582


Why c is called free form language?

542


a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);

620


Explain what are bus errors, memory faults, and core dumps?

761


Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?

573


What is the use of a conditional inclusion statement in C?

572


How to Throw some light on the splay trees?

594


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

625


I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.

1716