1 votes 1 votes What will be the output of following? main() { Static int a = 3; Printf(“%d”,a--); If(a) main(); } $3$ $3\;2\;1$ $3\;3\;3$ Program will fall in continuous loop and print $3$ Programming in C nielit2017oct-assistanta-it programming-in-c output + – admin asked Apr 1, 2020 edited Sep 29, 2020 by soujanyareddy13 admin 805 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
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 Vipin Tiwari answered Apr 2, 2020 Vipin Tiwari comment Share Follow See all 0 reply Please log in or register to add a comment.
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 . anjli answered Feb 6, 2021 anjli comment Share Follow See 1 comment See all 1 1 comment reply sra1kumarrevanthula commented Apr 1, 2021 reply Follow Share 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 votes 0 votes Please log in or register to add a comment.