LearnFrenzy
Sign in Take a free test

Typedef · typedef MCQ · Question 4

typedef char *String; – what is const String s? Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links