C pointer to array/array of pointers disambiguation

前端 未结 13 1391
我寻月下人不归
我寻月下人不归 2020-11-21 05:19

What is the difference between the following declarations:

int* arr1[8];
int (*arr2)[8];
int *(arr3[8]);

What is the general rule for under

13条回答
  •  盖世英雄少女心
    2020-11-21 06:10

    I guess the second declaration is confusing to many. Here's an easy way to understand it.

    Lets have an array of integers, i.e. int B[8].

    Let's also have a variable A which points to B. Now, value at A is B, i.e. (*A) == B. Hence A points to an array of integers. In your question, arr is similar to A.

    Similarly, in int* (*C) [8], C is a pointer to an array of pointers to integer.

提交回复
热议问题