ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
int main(void) {
char c = 200;
printf("%d", c);
}- A. Implementation-defined: on a platform where plain char is signed (the common case), 200 overflows the signed char range (-128 to 127) and the stored/printed value is typically -56
- B. -200
- C. It is always 56 on every platform
- D. 200
Correct answer: A. Implementation-defined: on a platform where plain char is signed (the common case), 200 overflows the signed char range (-128 to 127) and the stored/printed value is typically -56
Whether plain `char` is signed or unsigned is implementation-defined in C. On the common case (signed char, 8 bits, range -128..127), assigning 200 (outside that range) results in an implementation-defined conversion — typically wrapping to 200-256=-56 on two's-complement systems — rather than storing 200 directly, which doesn't fit.
More C Programming questions
- What is printed? c int main(void) { int a = 10; int p = &a; int pp = &p; printf("%d %d %d", a, p, pp); a = 20; printf(" %d %d %d", a, p…
- What is printed? c enum Color { RED, GREEN, BLUE }; enum Color c = GREEN; printf("%d", c); enum Status { OK = 1, FAIL = 5, PENDING }…
- What is printed? c int main(void) { int x = 1; int p = &x; p += 1; (p)++; ++p; printf("%d", x); }
- What is printed? c int main(void) { int x = 0; int y = (x = 5, x + 1); printf("%d %d", x, y); }
- What is printed? c int main(void) { int arr[3] = {1, 2, 3}; int p = arr; for (int i = 0; i < 3; i++, p++) { printf("%d ", p); } }
- Assume 32-bit int. What is printed? c int x = 7; int y = x > 5 && x < 10 ? x 2 : x + 1; printf("%d", y);