Question 9
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
char c = 'A';
printf("%zu %zu %zu\n", sizeof c, sizeof(c + 1), sizeof(c = 'B'));
printf("%c\n", c);
return 0;
}
- A 1 4 1 A Correct
- B 1 1 1 B
- C 1 4 4 A
- D 1 4 1 B
Correct Answer: Option A
c + 1 is promoted to int (4 bytes). The assignment expression has the type of c (1 byte) – and since sizeof never evaluates its operand, c is still 'A'.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!