#include <stdio.h>
int main()
{
int i = 3;
while (i--)
{
int i = 100;
i--;
printf("%d ", i);
}
return 0;
}
Answer: B
Correct answer: 99 99 99
The inner int i = 100; shadows the outer i for the whole of the loop body, so i-- and the printf refer to the new variable, which is created afresh at 100 on every pass and printed as 99. The outer i is untouched inside the body and is decremented only by the while condition, so the loop still runs three times.
Please log in or register to report this question.