ProgrammingHardHCL · Tech Mahindra pattern
Assume 32-bit int. What is printed?
Assume 32-bit int. What is printed?
unsigned char a = 200;
unsigned char b = 100;
unsigned char c = a + b;
printf("%u", c);- A. 300
- B. 44
- C. 255
- D. 200
Correct answer: B. 44
a and b are promoted to int for the addition (200+100=300), but the result is then stored back into an unsigned char, which wraps modulo 256: 300 mod 256 = 44. This is well-defined (unsigned types wrap, never undefined), unlike signed overflow.
More C Programming questions
- Assume 32-bit int. What is printed? c int flags = 0; flags |= (1 << 2); flags |= (1 << 5); flags &= ~(1 << 2); printf("%d", flags);
- Assume 32-bit int. What is printed? c int a = -1; unsigned int b = a; printf("%u", b);
- What is printed? (Assume no overflow trapping.) c int f(int n) { if (n == 0) return 0; return n + f(n - 1); } int main(void) {…
- What is printed? c int mystery(int a, int b) { if (b == 0) return a; return mystery(b, a % b); } int main(void) { printf("%d", mystery(48…
- What is printed? (Assume int is 32 bits, two's complement.) c unsigned int a = 0xF0F0F0F0; unsigned int b = a >> 4; printf("%X", b);
- What is printed? (Assume int is 32 bits, two's complement, arithmetic right shift for signed negatives — the common but…