edited by
244 views

1 Answer

0 votes
0 votes

First of all the syntax of the code is incorrect as either the declaration of the function should be given on the top or the function should be defined on the top itself.

Anyway, I am assuming its a "pseudo-code" kind of thing.

So, for "static" keyword.

 A static int variable remains in memory while the program is running. A normal or auto variable is destroyed when a function call where the variable was declared is over.

But the trick in this question is that “Nothing is passed in the function for every iteration of i”.

So, every time when the function will enter the “f()” part, then x will be equal to 5 every time, and it will be incremented to x++, i.e. 6 every time.

So, lastly, output printed will be 66666 as the “f()” function will be called 5 times in for loop from the "main()" function.

Related questions

0 votes
0 votes
1 answer
1