Differences when using ** in C

前端 未结 11 937
半阙折子戏
半阙折子戏 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:40

    C syntax is logical. As an asterisk before the identifier in the declaration means pointer to the type of the variable, two asterisks mean pointer to a pointer to the type of the variable.

    In this case arr is a pointer to a pointer to integer.

    There are several usages of double pointers. For instance you could represent a matrix with a pointer to a vector of pointers. Each pointer in this vector points to the row of the matrix itself.

    One can also create a two dimensional array using it,like this

     int **arr=(int**)malloc(row*(sizeof(int*)));  
     for(i=0;i

提交回复
热议问题