C ++ Pointer to a const array of constant pointers

I created an array of const pointer constants, for example:

const char* const sessionList[] = { dataTable0, dataTable1, dataTable2, dataTable3 }; 

What is the correct syntax for a regular non-const pointer for this array? I thought it would be const char** , but the compiler thinks differently.

+6
source share
3 answers
 const char* const sessionList[] = { ... }; 

better to write like:

 char const* const sessionList[] = { ... }; 

Type sessionList[0] - char const* const .
Therefore, the type &sessionList[0] is char const* const* .

You can use:

 char const* const* ptr = &sessionList[0]; 

or

 char const* const* ptr = sessionList; 

Declares a pointer to sessionList elements. If you want to declare a pointer to the entire array, this should be:

 char const* const (*ptr)[4] = &sessionList; 
+3
source

If you really need a pointer to an array, as your header suggests, then this is the syntax:

 const char* const (*ptr)[4] = &sessionList; 
+6
source

The same type as for array elements, an additional * added:

 const char* const * 
+2
source

All Articles