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

posted @ 2013-07-18 20:51  开心成长  阅读(412)  评论(0编辑  收藏  举报