What is the output of the following program?#include<stdio.h>
int main() {
int i = 3;
while (i--) {
int i = 10;
i--;
printf("%d", i);
}
printf("%d", i);
}
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: C. 999-1
Explanation
The outer i (3, 2, 1) makes the loop run 3 times. Each time a new inner i = 10 is decremented and 9 is printed, giving 999. The final test i-- takes the outer i from 0 to −1, so the last printf prints −1: 999-1.More Programming Languages and Computer Graphics questions
- The hue of a colour is related to its:
- What is the output of the following program?#include <stdio.h> #define SQR(x) (x*x) int main() { int a, b = 3; a = SQR(b+2); printf("%d", a…
- Consider the three points P1(1, 2, 0), P2(3, 6, 20) and P3(2, 4, 6) and a viewpoint C(0, 0, −10). Choose the correct options. (A) P1 obscur…
- Which of the statements are CORRECT? (A) Constructors are invoked automatically when objects are created. (B) Constructors do not have retu…
- Match List I with List IIList I List II (a) Bresenham (I) Hidden surface removal (b) Cohen-Sutherland algorithm (II) Line drawing (c) Suthe…
- Consider the following code segment:int arr[] = {0,1,2,3,4}; int i = 1, *ptr; ptr = arr + 2; Arrange the following printf statements in inc…