Is there a difference between a pointer parameter and an array parameter?

前端 未结 2 1699
[愿得一人]
[愿得一人] 2021-01-18 10:19

void method(double *v)

void method(double v[5])

Is there any difference between these two?

Is the second one more specific,

2条回答
  •  星月不相逢
    2021-01-18 10:59

    No and no.

    When in function arguments, they are the same, the compiler treats the argument double v[5] as a pointer. The size 5 is ignored, it's at most a signal for the programmer.

    C++ 11 §8.3.5 Functions Section 3

    [ ... ] After determining the type of each parameter, any parameter of type “array of T” or “function returning T” is adjusted to be “pointer to T” or “pointer to function returning T,” respectively.

提交回复
热议问题