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
What is d'n in c?
What do you mean by keywords in c?
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
What is the difference between formatted&unformatted i/o functions?
Is swift based on c?
What functions are used in dynamic memory allocation in c?
What is hash table in c?
What does typedef struct mean?
will u please send me the placement papers to my mail???????????????????
the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+....
pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice)
Can you please explain the scope of static variables?
Is it fine to write void main () or main () in c?
Is multithreading possible in c?
How do you redirect a standard stream?