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

const char *msg;
char* const msg;

thanks in advance)

Recommended Answers

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 …

Jump to Post

All 2 Replies

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;
commented: +++++ +1

Narue,many thanks for detailed answer and the third variant!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.