Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to understand const and pointer in C++ expression below?

I am reading application code developed in the IBM RSARTE C++ version. Here is a piece of C++ code:

const char * const * av = RTMain::argStrings();

How to understand the left-hand side syntax when there are two const and two *?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

const char * const * av = RTMain::argStrings();

is the same as

char const * const * av = RTMain::argStrings();

const applies to what’s left of const.

So, av is a non-const pointer to a const* to const char.

  • The returned pointer, av, is non-const and can be changed.
  • The pointer av is pointing at is const and can not be changed.
  • The char that pointer is pointing at is const and can not be changed.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading