Differences when using ** in C

前端 未结 11 955
半阙折子戏
半阙折子戏 2020-12-24 10:50

I started learning C recently, and I\'m having a problem understanding pointer syntax, for example when I write the following line:

int ** arr = NULL;
         


        
11条回答
  •  清酒与你
    2020-12-24 11:30

    Pointers do not keep the information whether they point to a single object or an object that is an element of an array. Moreover for the pointer arithmetic single objects are considered like arrays consisting from one element.

    Consider these declarations

    int a;
    int a1[1];
    int a2[10];
    
    int *p;
    
    p = &a;
    //...
    p = a1;
    //...
    p = a2;
    

    In this example the pointer p deals with addresses. It does not know whether the address it stores points to a single object like a or to the first element of the array a1 that has only one element or to the first element of the array a2 that has ten elements.

提交回复
热议问题