Question about variable definitions in functions.
- by Kaan Tekelioglu
Hi.
#include <stdio.h>
main()
{
int a;
for(a=1; a<=4 && printf("%d ",a); a++)
{
int a;
static int b=a;
printf("%d ",(a++)-b);
}
getchar();
getchar();
}
In this code, the printout is 1 0 2 1 3 2 4 3. I understand why the int a; part works differently then the int a which was defined outside the for function, and why static int b; is only defined once with the primary value of a ; but why does the (a++) part in printf affect proceeding values of a? Don't we redefine int a; each time the for function runs? Thanks in advance.