The following code I came across though I have basic idea of C. I still get the logic of below code.
How does the loop terminate and when does the loop terminate — at what condition?
At last
counter
becomes zero, but why doesn't the loop continue to execute with -1, -2 and instead it terminates?
Code:
#include <stdio.h>
void func(void);
static int count = 5;
int main()
{
while (count--)
{
func();
}
return 0;
}
void func(void)
{
static int i = 5;
i++;
printf("i is %d and count is %d\n", i, count);
}
Output:
i is 6 and count is 4
i is 7 and count is 3
i is 8 and count is 2
i is 9 and count is 1
i is 10 and count is 0