ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
unsigned char a = 250, b = 10, z = 0;
int s = a + b;
unsigned char t = a + b;
z--;
printf("%d %d %d", t, z, s);- A. 260 255 260
- B. 4 -1 260
- C. 4 255 4
- D. 4 255 260
Correct answer: D. 4 255 260
a + b is computed in int after integer promotion (260), so s keeps 260. Storing it back in an unsigned char reduces it mod 256 → 4. Decrementing an unsigned char 0 wraps to 255; unsigned arithmetic wrap-around is well defined.
More C Programming questions
- What is printed? c int x = 6; printf("%d %d", x & 2 == 2, (x & 2) == 2);
- What is printed? c int a = (1, 2, 3); int b = 5; b = (b + 1, b 2); printf("%d %d", a, b);
- What is printed? c void f(int n) { if (n > 0) { f(n - 1); printf("%d ", n); f(n - 2); } } int main(void) { f(3); }
- What is printed? c int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; printf("%d %d %d", ((a + 1) + 2), (a[1] + 1), a + 1);
- What is printed? c char s[] = "hello"; char p = s; printf("%zu %zu %zu", strlen(s), sizeof(s), sizeof(p)); / 64-bit system /
- What is printed? c int i = 10, c = 0; do { c++; i++; } while (i < 5); printf("%d %d", i, c);