edited by
1,305 views
4 votes
4 votes
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 by

1 Answer

Best answer
2 votes
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);
	}
}
selected by

Related questions

1 votes
1 votes
1 answer
1
Akriti sood asked Dec 20, 2016
317 views
#include<stdio.h int main() { int m[6] = {15, 11, 25, 30, 35, 45}; int p, q, r; p = ++m ; q = m ++; r = m[p++]; printf("%d, %d, %d", p, q, r); return 0; }
2 votes
2 votes
1 answer
2
Shivi rao asked Oct 11, 2017
498 views
What is the output of the following program?int main ( ){char *str = “Gate2018”printf (“%d”, output (str)) ;return 0;}int output(char *P1){char *P2 = P1 ;while (*...
0 votes
0 votes
0 answers
3
Anirudh Kaushal asked Apr 6, 2022
191 views
#include<stdio.h struct marks { int p:3; int c:3; int m:2; }; void main() { struct marks s = {2, -6, 5}; printf("%d %d %d", s.p, s.c, s.m); }What does p:3 means here ?
0 votes
0 votes
1 answer
4
Parshu gate asked Nov 19, 2017
359 views
#include<stdio.h>int main(){ int a=2;if(a==2){ a=~a+2<<1; printf("%d",a);}}