ProgrammingVery hardGATE CS · TCS NQT
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
signed char c = -1;
unsigned char d = c;
printf("%d %d", c == d, (int)d);
}- A. 1 255
- B. 0 -1
- C. 1 -1
- D. 0 255
Correct answer: D. 0 255
d holds 255 after conversion, and c is promoted to -1, which is not equal to 255. The comparison yields 0, and (int)d is 255.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int h = -17; unsigned idx = (unsigned)h % 16u; printf("%u", idx); }
- What is printed? c #include <stdio.h> #include <stdlib.h> #include <string.h> struct Person { char name[4]; int age; }; int cmp(const void…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {3, 1, 2, 5, 4}, c = 0; for (int i = 0; i < 5; i++) for (int j = i + 1; j…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint8t m = 0x0F; for (int i = 0; i < 8; i++) m = (uint8t)((m <<…
- What is printed? c #include <stdio.h> int main(void) { int x = 6; printf("%d", x & -x); }
- What is printed? c #include <stdio.h> int main(void) { const char s = " a bb ccc "; int words = 0, in = 0; for (; s; s++) { if (s == ' ')…