0

Hi friends!
What is the difference between these two definitions of variables?

const char *msg;
char* const msg;

thanks in advance)

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by vedro-compota
1

const char *msg is a pointer to const char. char* const msg is a constant pointer to char. In the former case the object being pointed to is const and cannot be modified, but the pointer can be changed to point to another object. In the latter case the pointer is const and cannot be pointed to another object, but the object being pointed to may be modified.

A third case could be where both are const:

const char* const msg;
Votes + Comments
+++++
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.