unsigned char i = 0, j(70), k = 10;
for (i = 8; i < 48; i += 7) {
j += k++;
}
printf("i = %d; j = %03d; k = %03d", i, j, k);
return 24;
Explain, please, why "i = 50"?
I thought it would i = 0;
>Solution :
Why would it be zero? You do start by assigning zero to it, but then you promptly assign 8 to it. Each pass of the loop adds 7 to it until it reaches 50 at the end of the 6th pass.
You might understand things better if you placed a copy of the printf statement at the start of the loop body.
Note that it would be zero if you had
unsigned char i = 0, j = 70, k = 10;
for (unsigned char i = 8; i < 48; i += 7) {
j += k++;
}
printf("i = %d; j = %03d; k = %03d", i, j, k);
As this creates a second variable named i that is scoped to the for loop.