ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
int a = 0;
int b = (a = 5) == 5;
printf("%d %d", a, b);- A. 0 1
- B. 5 1
- C. 0 0
- D. 5 0
Correct answer: B. 5 1
Assignment `(a = 5)` has lower precedence than ==, but the parentheses force it to be evaluated as a complete assignment expression first, yielding the value 5 and setting a=5; `5 == 5` is then true (1). a=5, b=1.
More C Programming questions
- What is printed? c #define ISEVEN(x) ((x) % 2 == 0) #define ISODD(x) (!ISEVEN(x)) int main(void) { int n = 7; printf("%d %d", ISEVEN(n)…
- What is printed? c int x = 7; int result = x % 2 == 0 ? x / 2 : x 3 + 1; printf("%d", result);
- What is printed? c #define PRINT(x) printf(#x " = %dn", x) int main(void) { int count = 5; PRINT(count); }
- What is printed? c #define MULTILINE(x) do { x = x 2; x = x + 1; } while (0) int main(void) { int v = 5; MULTILINE(v); printf("%d", v); }
- What is printed? c #define DEBUGPRINT(fmt, ...) printf(fmt, VAARGS) int main(void) { DEBUGPRINT("%d and %dn", 1, 2); }
- What is printed? c #define SAFEDIV(a, b) ((b) != 0 ? (a) / (b) : 0) int main(void) { int x = 10, y = 0; printf("%d", SAFEDIV(x, y)); }