Question 9
Back to Exercise
What is the output of the following C program on a 64-bit system?
#include <stdio.h>
int main(void) {
char a[] = "hello";
char b[10] = "hello";
const char *c = "hello";
printf("%zu %zu %zu\n", sizeof a, sizeof b, sizeof c);
return 0;
}
- A 6 10 8 Correct
- B 5 10 5
- C 6 6 6
- D 6 10 6
Correct Answer: Option A
a gets exactly 6 bytes from the string, b the 10 bytes declared, and c is a pointer (8 bytes). The declaration, not the string, decides the size.
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!