390 views
1 votes
1 votes
as i is initialized with 5 in main then how it becomes 0

please explain ?

int main()
{
static int i=5;
if(--i)

{
main();
printf("%d ",i);
}

}

op = 0000

2 Answers

Best answer
1 votes
1 votes

int main()
{
static int i=5; // only one time memory declare use same remaining time.
if(--i)  //start decreasing value of i by 1 at a time

{
main();   this happen before printing function means when i becomes 0 then all printf will start printing
printf("%d ",i);
}

}
 

selected by
2 votes
2 votes

As all printf prints after i becomes 0, so output will be 0000

Related questions

0 votes
0 votes
1 answer
1
2 votes
2 votes
2 answers
4
atulcse asked Jan 15, 2022
662 views
Consider the following programint find (int n) { int a = 1; for (i = 1; i < = n; i ++) for (j = 1; j < = i; j++) for (k = 1; k <= j, k++) a = a + 1; ...