standard conversions: Array-to-pointer conversion

后端 未结 4 1410
予麋鹿
予麋鹿 2020-11-29 10:33

This is the point from ISO :Standard Conversions:Array-to-pointer conversion: $4.2.1

An lvalue or rvalue of type “array of N T” or “array o

4条回答
  •  伪装坚强ぢ
    2020-11-29 11:10

    One example of this is that any array variable will automatically degenerate into a pointer to it's first element when passed to a function which takes a pointer of the array's type.

    Take a look at this section from the C-Faq on Arrays and Pointers. This is equally applicable in C++.

    void foo(int *a) {
        a[0] = 1;
    }
    
    int main(void) {
        int b[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    
        foo(b);
    
        printf("b[0] == %d\n", b[0]);
    }
    

提交回复
热议问题