in Programming in C edited by
811 views
1 vote
1 vote

What will be the output of following?

main()

{

         Static int a = 3;

         Printf(“%d”,a--);

         If(a)

         main();

}
  1. $3$
  2. $3\;2\;1$
  3. $3\;3\;3$
  4. Program will fall in continuous loop and print $3$
in Programming in C edited by
by
811 views

2 Answers

3 votes
3 votes
option B will be correct

Because memory for static variables is created only one time.

a-- is post decrement operation of value of a will be printed then it is decremented.

after printing 3 2 1 a value become 0.

so if(a) condition fails and program terminates
0 votes
0 votes
Ans : B

a is having post decrement  operation

Firstly value of a is  printed and then decrement operation of a will be printed .

so ,print value of a :3,2,1 ,after 1 the value of a become 0 ,condition become false  and programm terminates .
by

1 comment

for static variables, memory is initialized once and it keeps track the value of variable,

so here a initialized with 3 , prints 3 1st which is post decremented and if true it goes to main function.

here static already holds the value of a i.e 2 , and prints 2 and now if condition is checked and goes to main and this main function is called till if condition is true i.e a value should be 1.

so output is 3 2 1
0
0
Answer:

Related questions