Question 11
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
printf("%zu %zu\n", sizeof 'A', sizeof ((char) 'A'));
return 0;
}
- A 1 1
- B 4 1 Correct
- C 4 4
- D 1 4
Correct Answer: Option B
In C a character constant such as 'A' has type int, so its size is 4. Cast to char, it is 1. (In C++, 'A' is a char and its size is 1 – a favourite interview trap.)
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!