Question 6
Back to Exercise
What is the output of the following C program on a 64-bit system?
#include <stdio.h>
typedef char *String;
int main(void) {
char word[] = "abc";
const String s = word;
s[1] = 'B';
printf("%s\n", s);
return 0;
}
- A aBc Correct
- B abc
- C Compilation error: s is const
- D Bbc
Correct Answer: Option A
const String s is char *const s: the pointer is fixed, but the characters it points to are modifiable. Re-pointing s (s = other;) would be the compile error.
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!