ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int a = 1, b = 2, c = 3;
a += b -= c *= 2;
int d = (a, b) > c ? a-- : c++;
printf("%d %d %d %d", a, b, c, d);- A. -3 -4 6 7
- B. 3 -4 7 6
- C. -3 -4 7 6
- D. -4 -4 7 6
Correct answer: C. -3 -4 7 6
Assignment operators group right to left: c *= 2 makes c 6, b -= 6 makes b −4, a += −4 makes a −3. In (a, b) the comma operator discards a and yields b = −4; −4 > 6 is false, so the third operand c++ is evaluated: d gets the old value 6 and c becomes 7. a-- is never evaluated, so a stays −3.
More C Programming questions
- What is printed? c int a[] = {1, 2, 3, 4, 5}; int p = a + 1, q = &a[4]; printf("%td %d %d", q - p, p + q, p[2]);
- With 4-byte int, what is printed? c int a[3][4] = {0}; int (p)[4] = a; int q = &a[0][0]; printf("%td %td %td", (p + 2) - p, (char )(p + 1)…
- What is printed? c int calls = 0; int f(int n) { calls++; return n < 2 ? n : f(n / 2) + f(n - 1); } int main(void) { int r = f(6)…
- Assume 32-bit unsigned int. What is printed? c unsigned x = 0xB8; / 1011 1000 / printf("%u %u %u", x & (x - 1), x | (x - 1), x & -x);
- What is printed? c int f(void) { static int n = 5; return n--; } int main(void) { int s = 0; while (f() > 2) s++; printf("%d %d", s, f()); }
- What is printed? c #define MUL(a, b) a b #define ADD(a, b) a + b printf("%d", MUL(ADD(1, 2), ADD(3, 4)));