指针,这里不太懂,有哪位大佬说下吗?
#include <stdio.h>void f(int * pArr, int len)
int main(void)
{
int a[5]={1, 2, 3, 4, 5};
int b[6]={-1, -2, -3, 4, 5, -6};
int c[100]={1, 99, 22, 33};
f(a,5);
return 0;
}
f(a,5) a 为什么是int * 类型的?
程序代码:
void g(int (&a)[3])
{
std::cout << a[0] << '\n';
}
void f(int* p)
{
std::cout << *p << '\n';
}
程序代码:
int a[3] = {1, 2, 3};
int* p = a;
...
// where arrays are acceptable, but pointers aren't, only arrays may be used
g(a); // okay: function takes an array by reference
// g(p); // error
...
// where pointers are acceptable, but arrays aren't, both may be used:
f(a); // okay: function takes a pointer
f(p); // okay: function takes a pointer