ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
int i = 0;
while (i++ < 5);
printf("%d", i);- A. 6
- B. Nothing: it loops forever
- C. 4
- D. 5
Correct answer: A. 6
The semicolon is an empty loop body. The test compares the old value and then increments: it succeeds for 0 to 4, and the failing test (5 < 5) still increments i to 6.
More C Programming questions
- What is printed? c #define LEVEL 2 #if LEVEL > 1 #define MSG "high" #elif LEVEL > 0 #define MSG "low" #endif #undef LEVEL #ifndef LEVEL…
- What is printed? c struct E { char name[8]; int age; }; struct E t[] = {{"Asha", 31}, {"Bilal", 27}, {"Chen", 45}, {"Dev", 22}}; struct E…
- What is printed? c int f(int a, int n) { if (n == 1) return a[0]; int m = f(a + 1, n - 1); return a[0] > m ? a[0] - m : m - a[0]; } int…
- What is printed? c printf("%.1f", 1 ? 3 : 2.5);
- What is printed? c int a = 0, b = 10; while (a < b) { a += 3; b -= 2; } printf("%d %d", a, b);
- After int q = realloc(p, 2 n sizeof q); succeeds (q is not NULL), where p pointed to n ints, which statement is true?