Question 4
Back to Exercise
Given typedef char *String;, what is const String s;?
- A const char *s – the characters are read-only
- B char *const s – the pointer is read-only, the characters are not Correct
- C const char *const s
- D It does not compile
Correct Answer: Option B
A typedef is not a text substitution: const qualifies the whole type String, which is a pointer. So the pointer becomes const. For read-only characters write typedef const char *CString;.
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!