Initializing “a pointer to an array of integers”

后端 未结 4 382
一整个雨季
一整个雨季 2020-12-14 03:27
 int (*a)[5];

How can we Initialize a pointer to an array of 5 integers shown above.

Is the below expression correct ?

int          


        
4条回答
  •  再見小時候
    2020-12-14 03:27

    int vals[] = {1, 2};
    int (*arr)[sizeof(vals)/sizeof(vals[0])] = &vals;
    

    and then you access the content of the array as in:

    (*arr)[0] = ...
    

提交回复
热议问题