ProgrammingHardGATE CS
What is printed? Assume int is 32 bits and unsigned char is 8 bits.
What is printed? Assume int is 32 bits and unsigned char is 8 bits.
#include <stdio.h>
int main(void) {
unsigned char c = 0x0F;
printf("%d %d %d", ~c, (unsigned char)~c, ~c & 0xFF);
return 0;
}- A. 240 240 240
- B. -16 240 15
- C. -16 240 240
- D. -16 -16 240
Correct answer: C. -16 240 240
c is promoted to int (15) before ~, so ~c is -16 (all high bits set). Converting back to unsigned char keeps the low 8 bits, 0xF0 = 240, and masking with 0xFF also gives 240.
More C Programming questions
- What is printed? Assume int and unsigned int are 32 bits. c #include <stdio.h> int main(void) { int a = -1; unsigned int b = 1; printf("%d…
- What is the value printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned x = 0xB6D9 ^ 0x00FF; int n = 0…
- What is printed? c #include <stdio.h> #define MAX(a, b) ((a) > (b) ? (a) : (b)) int main(void) { int i = 3, j = 5; int m = MAX(i++, j++)…
- What is printed? c #include <stdio.h> int f(int n) { static int c = 0; c++; if (n >= 2) { f(n - 1); f(n - 2); } return c; } int main(void)…
- What is printed? Assume pointers are 8 bytes and the string literal's characters are those between the quotes. c #include <stdio.h>…
- What is the exact output? c #include <stdio.h> int main(void) { int n = printf("%d%d", 12, 345); printf("|%d", n); return 0; }