ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
int x = 0;
if (x == 1);
x += 5;
printf("%d", x);- A. 1
- B. 5
- C. 6
- D. 0
Correct answer: B. 5
The semicolon right after the if is an empty statement, which is all the if controls. The indented x += 5 is an ordinary statement that always runs. The indentation misleads; C ignores it.
More C Programming questions
- What is printed? c int inc(int x) { return x + 1; } int dec(int x) { return x - 1; } int (pick(int c))(int) { return c ? inc : dec; } int…
- What is printed? c #include <limits.h> printf("%u %d", UINTMAX + 1u, UINTMAX == -1);
- What is printed? c int ways(int a, int n, int t) { if (t == 0) return 1; if (n == 0 || t < 0) return 0; return ways(a + 1, n - 1, t…
- What value does this call to printf return? c printf("%5.1f|%-5d|", 3.14159, 42);
- What is printed? c const char w[] = {"red", "green", "blue", "cyan"}; const char p[] = {w + 2, w, w + 3, w + 1}; const char q = p…
- What is printed? c int m(int n) { return n > 100 ? n - 10 : m(m(n + 11)); } int main(void) { printf("%d %d", m(50), m(105)); }