Why is it possible to:

int a = 1, b = 2, c = 3; int A[] = {a, b, c}, B[] = {c, b, a}; 

and so it is impossible:

 int a = 1, b = 2, c = 3; int* A[] = {&a, &b, &c}, B[] = {&c, &b, &a}; 

And also: why it’s impossible to declare an array of links ?

    3 answers 3

    You get an error when you declare an array B type int , and not a pointer to type int . The first asterisk refers to the first declaration of array A , and it has nothing to do with the second array, so you must specify it a second time before declaring array B like this:

     int main(){ int a = 1, b = 2, c = 3; int * A[] = {&a, &b, &c}, * B[] = {&a, &b, &c}; return 0; } 

      And why can not you declare an array of links?

      With the resolution of “link arrays” within the C ++ language, a lot of conceptual problems would appear. In C ++, reference types are not object types and do not formally occupy memory (i.e., the language does not specify whether the references occupy memory). For this reason, in particular, in the language there are no pointers to links and it is impossible to know the "size" of the link through sizeof .

      And the absence of pointers to links right there in itself “blocks” the possibility of creating arrays of links, because in C ++ (as in C) all the main functionality of the built-in arrays is fundamentally tied to the possibility of an array-to-pointer conversion, i.e. the possibility of forming pointers to the elements of the array and performing address arithmetic on them.

        Rewrite a little differently:

         int *A[] = {&a, &b, &c}, B[] = {&c, &b, &a}; 

        And it became clear why. The * sign applies only to the first ad.

        • 3
          The same situation arises when declaring something like int* a, b - here only a declared with a pointer, but b is a normal int , read as int *a, b - yeputons