What will be the output of the following C code? int main()
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 1;
while (i < 5) {
printf("%d ", i++);
i++;
}
return 0;
}
Show answerHide answer
Correct answer: (C) 1 3
Explanation
i = 1 is printed and becomes 2, then i++ makes it 3; 3 is printed and becomes 4, then 5. Now 5 < 5 is false, so the output is 1 3.