Differences when using ** in C

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

    How can I know if :

    arr is a pointer to a pointer of an integer

    arr is a pointer to an array of pointers to integers

    arr is a pointer to an array of pointers to arrays of integers

    You cannot. It can be any of those. What it ends up being depends on how you allocate / use it.

    So if you write code using these, document what you're doing with them, pass size parameters to the functions using them, and generally be sure about what you allocated before using it.

提交回复
热议问题