c++ - How to understand foo(char (&p)[10])? -
#include <iostream> void foo(char (&p)[10]) { printf("%d\n", sizeof(p)); } char p[10] = "aaa"; int main() { foo(p); }
that code output 10
, can't understand.
what meaning of char (&p)[10]
here?
the argument function foo
reference (&
) char
array of 10 elements (char ... [10]
). name of argument p
. reference means specify argument as-is (no pointer or address needed), calling foo(p)
in main
correct way given how p
declared. function foo
prints 10 because argument 10 bytes in size.
Comments
Post a Comment