Function returning a pointer to an int array

前端 未结 2 1980
长情又很酷
长情又很酷 2021-01-14 00:24

I am learning C++ from Primer 5th edition and I am at Returning a Pointer to an Array. The declaration of this function is:

 int (*func(int i))[10]; 
         


        
2条回答
  •  囚心锁ツ
    2021-01-14 01:09

    int(*)[10] is a pointer to an array of 10 ints. int* is a pointer to int. These are different types.

    However, an array decays to a pointer to its first element, so you can do:

    int a[10];
    int(*p)[10] = &a;
    int* q = a; // decay of int[10] to int*
    

    But not:

    q = p;
    p = q;
    

提交回复
热议问题