ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
int x = 4;
if (x & 1 == 0) printf("even");
else printf("odd");- A. Compilation error
- B. Nothing
- C. even
- D. odd
Correct answer: D. odd
== has higher precedence than &, so the test is x & (1 == 0) = 4 & 0 = 0, which is false, and the even number 4 is reported as odd. Write (x & 1) == 0.
More C Programming questions
- What is printed? c int f(int n) { static int s = 0; s += n; if (n > 0) f(n - 1); return s; } ... printf("%d ", f(3)); printf("%d", f(3));
- What is printed? c printf("%d", 2 + 3 << 1 & 7);
- How many of these are correct in C? (i) A global variable without an initialiser starts as 0. (ii) A static local variable is initialised…
- What is f in the declaration int (f)(int); ?
- What is printed? c int a[] = {5, 10, 15}; int p = a; int x = p++; int y = (p)++; int z = ++p; printf("%d %d %d %d", x, y, z, a[1]);
- With 32-bit unsigned int, what is printed? c unsigned int x = 0; x--; printf("%u %d", x, x > 0);