C++_数组作为参数传递
#include<iostream> using namespace std; void Foo1(int arr[3]) { cout << "pass by pointer: " << sizeof(arr) << endl; } void Foo2(int (&arr)[3]) { cout << "pass by reference: " << sizeof(arr) << endl; } void Foo3(int *arr) { cout << "pass by ppinter: " << sizeof(arr) << endl; } void main() { int a[3]={2,8,6}; cout << "In main function : " << sizeof(a) << endl; Foo1(a); Foo2(a); Foo3(a); }
输出:
In main function:12
pass by pointer:4
pass by reference:12
pass by pointer:4