ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
int a = 2, b = 3, c = 4;
printf("%d %d %d", a + b * c % 5 - -a, a < b < c, c > b > a);- A. 5 1 1
- B. 6 1 1
- C. 6 1 0
- D. 3 1 0
Correct answer: C. 6 1 0
* and % share a precedence level and group left to right: (3 * 4) % 5 = 2, so 2 + 2 − (−2) = 6. Relational operators also group left to right and yield 0 or 1: a < b < c is (2 < 3) < 4 → 1 < 4 → 1, but c > b > a is (4 > 3) > 2 → 1 > 2 → 0. C does not chain comparisons the way mathematics does.
More C Programming questions
- What is printed? c char w[] = {"red", "green", "blue"}; char p = w + 1; printf("%c %s %c %zu", p, (p + 1) + 2, ((p - 1) + 1), strlen(p[1])…
- What is printed? c struct { unsigned a : 3; unsigned b : 5; } f = {0, 0}; f.a = 9; f.b = 33; printf("%u %u ", f.a, f.b); f.a += 7; f.b =…
- What is printed? c / 32-bit unsigned int / unsigned np2(unsigned v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >>…
- What is printed? c / 8-bit unsigned char, 32-bit int / unsigned char c = 0x80; printf("%d %d %d %d", c << 1, (unsigned char)(c << 1), ~c…
- What is printed? c char s[] = "a,b,,c"; int n = 0; for (char t = strtok(s, ","); t; t = strtok(NULL, ",")) n++; printf("%d %zu %c", n…
- What is printed? c char s[] = "Hello"; s[0] = 'J'; s[4] = '0'; printf("%s %zu", s, sizeof(s));