Correct option is C
The program uses the
post-increment operator (i++) both in the for loop condition and inside the printf() statement. Initially, i = 0. In the first condition, i++ < 10 compares 0 with 10 and then increments i to 1; therefore, printf("%d", i++) prints
1 and increments i to 2. The same process repeats, causing the values
1, 3, 5, 7 and 9 to be printed. After printing 9, i becomes 10, and the next condition 10 < 10 becomes false. Hence, the output is
13579.
Information Booster
1.
Post-increment (i++)
· The post-increment operator first
uses the current value of the variable and then increments it by 1.
· For example:
int i = 5;
printf("%d", i++);
prints 5, after which i becomes 6.
2.
Evaluation of the for condition
· The condition is:
i++ < 10
· The comparison uses the
old value of i.
· After the comparison, i is incremented.
· Thus, every successful condition check increases i by 1 before entering the loop body.
3.
Evaluation inside printf()
· The statement:
printf("%d", i++);
prints the current value and then increments i.
· Therefore, the value of i increases
twice per successful iteration: once in the condition and once in the loop body.
4.
Iteration-wise execution
| Iteration |
Value tested in condition |
i after condition |
Value printed |
i after printf() |
| 1 |
0 |
1 |
1 |
2 |
| 2 |
2 |
3 |
3 |
4 |
| 3 |
4 |
5 |
5 |
6 |
| 4 |
6 |
7 |
7 |
8 |
| 5 |
8 |
9 |
9 |
10 |
| 6 |
10 |
11 |
— |
— |
· Since the printf() statement contains no spaces or newline:
13579
· Conceptually, the printed sequence is 1, 3, 5, 7, 9.
Additional Knowledge
· Important C-language point: In this program, the two i++ operations occur in separate full expressions—the for condition and the printf statement—so there is no unsequenced modification issue between these two increments.
· When you see i++ in both the for condition and the loop body, trace the value after each increment separately rather than assuming the loop variable increases only once per iteration.