184 views
main () {
if(--i) {
main ();
printf("%d", i);
}
}
1.   5 4 3 2 1
2.   1 2 3 4 5
3.   0 0 0 0 0
4.   Compiler error
edited | 184 views
+1
stack overflow

So, compiler error.

main() will call infinite time
0
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
+1

yes yes that error will show

http://ideone.com/3zZP0r

// 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);
}
}
selected
0
@debashish,why is there an error in your second example..??because in every call,i will be equal to 5..right?
0
not error ..only stackoverflow
0
and what about my question??if nothing is mentinoed for 'i',then what will be the answer?
0

'i' undeclared error should be .. or what else can be? :)

0
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.