Q28.Marks: +2.0UGC NET Paper 2: Computer Science and Application 26th June 2025 Shift 1
What will be the output of the following C programming code:
int i, j;
for(i = 1; i < 5; i += 2)
for(j = 1; j < i; j += 2)
printf("%d", j);
1.1✓ Correct
2.1 2
3.1 3
4.1 1 3
Solution
The correct answer is 1
Key Points
Code (formatted):
int i, j;
for (i = 1; i < 5; i += 2) // i: 1, 3
for (j = 1; j < i; j += 2) // j starts at 1 for each i
printf("%d", j); // prints j with no spaces/newline
No braces ⇒ the inner for loop is the single statement body of the outer loop, and printf is the single statement body of the inner loop.
The inner loop re-initializes j = 1 for each value of i, and then prints all odd j values that are strictly less thani (because j += 2).