Difference between pointer to pointer and pointer to array?

前端 未结 3 1000
一整个雨季
一整个雨季 2020-12-05 15:18

Given that the name of an array is actually a pointer to the first element of an array, the following code:

#include 

int main(void)
{
    in         


        
3条回答
  •  执念已碎
    2020-12-05 15:49

    Line 11 is

            p1 = &a;
    

    where p1 has type int ** and a has type int[3], right?

    Well; &a has type int(*)[3] and that type is not compatible with int** as the compiler told you

    You may want to try

            p1 = &p0;
    

    And read the c-faq, particularly section 6.

    In short: arrays are not pointers, and pointers are not arrays.

提交回复
热议问题