4 4 votes main () { if(--i) { main (); printf("%d", i); } } 5 4 3 2 1 1 2 3 4 5 0 0 0 0 0 Compiler error Programming in C programming-in-c data-structures + – Akriti sood 2.1k views answer comment Share Follow Print See all 3 Comments 3 3 Comments reply srestha commented Dec 28, 2016 reply Follow flag stack overflow So, compiler error. main() will call infinite time 1 1 replyShare Akriti sood commented Dec 28, 2016 reply Follow flag but here 'i is not defined,and even if we assume i to be 0 as default value then why will it enter if() loop as condition will be false 0 0 replyShare srestha commented Dec 28, 2016 reply Follow flag yes yes that error will show http://ideone.com/3zZP0r 1 1 replyShare Please log in or register to add a comment.
Best answer 2 2 votes // assuming i is defined // output 4 zeros #include <stdio.h> int i=5; int main() { if(--i) { main(); printf("%d\n",i); } } // assuming i is defined // runtime stack overflow : error #include <stdio.h> int main() { int i=5; if(--i) { main(); printf("%d\n",i); } } // assuming i is defined // output 4 zeros #include <stdio.h> int main() { static int i=5; if(--i) { main(); printf("%d\n",i); } } dd answered Dec 28, 2016 • selected Dec 28, 2016 by Akriti sood dd comment Share Follow See all 6 Comments 6 6 Comments reply Show 3 previous comments dd commented Dec 28, 2016 reply Follow flag 'i' undeclared error should be .. or what else can be? :) 0 0 replyShare Abhi Girin commented Sep 24, 2017 reply Follow flag in the third example, static int 5 , why its outputting 4 zeroes? my doubt is that after five levels in the recursion tree, value of i becomes 0 and if condition becomes false. please explain? 0 0 replyShare SURYA TEJA 1 commented Dec 13, 2019 reply Follow flag When will be output 4321? 0 0 replyShare Please log in or register to add a comment.