Question 8
Back to Exercise
What type does the string literal "hi" have in C?
- A const char[3]
- B char[3] – not const, but modifying it is still undefined behaviour Correct
- C char *
- D const char *
Correct Answer: Option B
For historical reasons, string literals are char arrays in C (they are const char arrays in C++). So char *s = "hi"; compiles without a warning, but writing through s is undefined. Declare const char *s.
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!