LearnFrenzy
Sign in Take a free test

C Const · const MCQ · Question 7

Passing const char * to a char * parameter Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 7 Back to Exercise

A function is declared void edit(char *s);. What happens when you call edit(msg) with const char *msg?

  • A Nothing special
  • B The const qualifier is discarded; the compiler warns, because edit() could write to read-only data Correct
  • C msg is copied
  • D It is converted safely
Correct Answer: Option B

Adding const is implicit and safe (char * → const char *); removing it is not. The fix is to make edit() take const char * if it does not write, or pass a modifiable copy.

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