What is the output of this C code?
void main()
{
int i = 0, j = 0;
for (i = 0;i < 5; i++)
{
for (j = 0;j < 4; j++)
{
if (i > 1)
break;
}
printf("Hi \n");
}
}
Answer: A
Correct answer: Hi is printed 5 times
The printf is outside the inner loop but inside the outer one, so it runs once per outer iteration - five times in all. The break only ever escapes the inner loop, and even then it changes nothing visible: whether the inner loop runs four times or stops at once, the outer loop still completes its five passes.
Please log in or register to report this question.