The following program:
#include <stdio.h>
int main()
{
char i='u';
for (int i=0;i<=3;i++)
{
printf("%d\n",i);
}
return 0;
}
prints 0,1,2,3 in new lines, since the character variable i
declared outside the for loop is "hid". But, the following program:
#include <stdio.h>
int main()
{
char i='u';
for (int i=0;i<=3;i++)
{
int i=8;
printf("%d\n",i);
}
return 0;
}
print 8 '4' times on new lines as if the variable i
initialized as 8 has more priority than the variable i
(counter) going from 0 to 3 .
The i
in the for initialization and the i
in the for loop are in the same block, but one seems to have more priority than the other. Does such a priority really exist and if yes, is there a defined order of priority?