1 votes 1 votes as i is initialized with 5 in main then how it becomes 0 please explain ? int main() { static int i=5; if(--i) { main(); printf("%d ",i); } } op = 0000 tiger asked Nov 29, 2015 tiger 390 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 1 votes 1 votes int main(){static int i=5; // only one time memory declare use same remaining time.if(--i) //start decreasing value of i by 1 at a time{main(); this happen before printing function means when i becomes 0 then all printf will start printingprintf("%d ",i);}} Prashant. answered Nov 29, 2015 selected Dec 4, 2015 by Pooja Palod Prashant. comment Share Follow See 1 comment See all 1 1 comment reply tiger commented Nov 29, 2015 reply Follow Share yes thanx got it 0 votes 0 votes Please log in or register to add a comment.
2 votes 2 votes As all printf prints after i becomes 0, so output will be 0000 srestha answered Nov 29, 2015 srestha comment Share Follow See all 2 Comments See all 2 2 Comments reply admin commented Nov 29, 2015 reply Follow Share because there is only one memory location for $i$, being a static variable. 1 votes 1 votes srestha commented Nov 29, 2015 reply Follow Share yes 1 votes 1 votes Please log in or register to add a comment.