What will be the output of the following program?
#include<stdio.h>
int main()
{ int i;
for (i = 0; i++<10; )
printf("%d", i++);
return 0;
}
int main()
{ int i;
for (i = 0; i++<10; )
printf("%d", i++);
return 0;
}
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: C. 1 3 5 7 9
Explanation
The for-loop has no explicit update clause; both increments happen via the condition (i++<10) and the body (printf with i++). Starting at i=0: the condition test increments i to 1 (test used old value 0, true), the body prints 1 then increments i to 2. Next condition test uses i=2 (true), increments to 3; body prints 3, increments to 4. This pattern continues, printing 1, 3, 5, 7, 9, after which the condition test uses i=10 (10<10 is false) and the loop ends. So the output is 1 3 5 7 9, option (3).More Programming Languages and Computer Graphics questions
- Match the LIST-I with LIST-II. LIST-I LIST-II A. Pivot point I. Reflection B. Fixed point II. Shear C. Mirror image III. Rotation D. Distor…
- The number of pixel columns divided by the number of scan lines that can be displayed by the system, is called
- The above figure shows a triangle at an original position (vertices labelled 2, 1, 3) to the left of the y-axis, and the same triangle, fil…
- 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);
- What would be the equivalent pointer expression for referring the array element ar[m][n][0]?
- Which of the following techniques is used for Clipping?