C / C ++: a constant array of constant arrays

What will be the syntax for creating a constant array of constant arrays?

I want the function argument to be a constant array of constant strings char*.

+3
source share
4 answers

You do this by placing to the constright of the first asterisk, for example

void f(const char *const *argument)

or equivalent

void f(const char *const argument[])

For a larger size, just add more *const(in this case, I would not use an alternative []):

void f(const char *const *const *argument) // 2D array of strings
+6
source

The key to this is writing C ++ backward (from right to left):

         char * const myVar[10] const;

... which says that myVar is the length of a const array of 10 constant pointer to char.

+4
source

,

const char* const array[size][size] = { /* initializer */ }

, .

+1

: () ?

C-

const char array[2][14] = { "first string", "second string" };

To define a constant array of non-string type constant arrays, the initializer is different:

const int array[2][3] =
{
  { 1, 2, 3 },
  { 4, 5, 6 }
};

(If necessary, you must make an array static const.)

0
source

Source: https://habr.com/ru/post/1783344/


All Articles