How it's output comes to 00? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How it's output comes to 00?

int main() { static int x=3; if(--x){ main(); printf("%d ",x); } }

11th Sep 2020, 6:58 AM
Suparna Podder
Suparna Podder - avatar
2 Answers
+ 5
You calling main function again and again it like a recursive type x=3 in if condition if(--x) here x will decrease means if(2) which is true after that u wrote main function so control will go again to main function then it will check condition if(--x) but x was 2 so if(--1) then maing again calling same process last value will be 0 and after that 0 0 0 will return .
11th Sep 2020, 7:13 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
recursion tree: If(2) | ------------ | | If(1) printf (x) | ------------ | | If(0) printf (x) Finally x value becomes zero so it will print 00 as an output (Inorder parsing)
16th Sep 2020, 4:27 PM
kishor pawar
kishor pawar - avatar