ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
int x = 255;
unsigned char y = (unsigned char)(x << 1);
printf("%d", y);- A. 510
- B. 254
- C. 0
- D. 256
Correct answer: B. 254
x<<1 as an int is 510 (0x1FE). Truncating to unsigned char keeps only the low 8 bits: 0x1FE & 0xFF = 0xFE = 254.
More C Programming questions
- What is printed? c int x = 5, y = 9; int max = y ^ ((x ^ y) & -(x < y)); printf("%d", max);
- What is printed? c int x = 101; int y = (x >> 2) << 2; printf("%d", y);
- What is printed? c #include <stdio.h> int main(void) { int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (p)[3] = a; printf("%d %d", ((p + 1))[2]…
- Assume a 64-bit ABI with 4-byte int. What is printed? c #include <stdio.h> int main(void) { int a[4]; int p = a; char cp = (char )a…
- What is printed? c #include <stdio.h> int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int main(void) { int…
- What is printed? c #include <stdio.h> void set(int pp) { static int x = 99; pp = &x; } int main(void) { int y = 5; int p = &y; set(&p)…