Help in finding output

can anyone please explain the logic behind this

If you don’t understand what static means, here is a nice article you may go through. The rest is just plain recursion where the value of i keeps pre-decrementing starting from 5 till we reach the base case, where i equals 0 and we print "0 " (with the blank space at the end) as we go up the function call stack. It gets printed 4 times as i gets decremented 5 times in 5 recursive function calls, but the last call does not count in terms of printing purpose as we don’t enter the if block as 0 evaluates to false. :slightly_smiling_face:

2 Likes

As a bit of language trivia: calling main from within main is one of the few things that is allowed in C but which is specifically disallowed in C++.

2 Likes