pointers and const

Feb 12, 2019 at 9:32pm
I am confused by this variable:

const char *const amplifierGPIO = "/sys/class/gpio/gpio107/value";

What does it mean to have *const? Is amplifierGPIO a pointer? A constant pointer maybe?
Last edited on Feb 12, 2019 at 9:32pm
Feb 12, 2019 at 9:41pm
Read from right to left.

const char  *  const  amplifierGPIO
     4      3    2          1

amplifierGPIO is a const pointer to a const char
      1              2      3              4
Last edited on Feb 12, 2019 at 9:42pm
Feb 12, 2019 at 10:29pm
Would it be the same if I said:

const char const* amplifierGPIO instead?
Feb 12, 2019 at 10:52pm
It doesn't matter in which order you put the words that are on the right side of the rightmost *.

Both of these mean the same thing.
1
2
const char* amplifierGPIO;
char const* amplifierGPIO;

But you are not allowed to repeat the words so this would give you an error.
 
const char const* amplifierGPI; // error: duplicate 'const' 
Last edited on Feb 13, 2019 at 8:56am
Topic archived. No new replies allowed.