] > Parameter Passing

10.6 Parameter Passing

#include <iostream> 
using namespace std; 
 
void show(int []); 
void change(int []); 
 
int main() 
{ 
  int x[5]={0,1,2,3,4}
  show(x); 
  change(x); 
  show(x); 
} 
 
void change(int a[]) 
{ 
  int b[5] = {7,8,9,10,11}
  a[0] = 999; 
  a = b; 
} 
 
void show(int a[]){ 
  for(int i = 0; i < 4; i++) 
  { 
     if( a[i] < 10 ){ cout << ’ ’; } 
     cout << a[i] << ’ ’; 
  } 
  cout << endl; 
}
 0  1  2  3  
999  1  2  3

#include <iostream> 
using namespace std; 
 
void show(int [][3]); 
 
int main() 
{ 
   int a[][3] = { 
     {0, 1, 2}
     {3, 4, 5} 
   }
   show(a); 
 
   return 0; 
} 
void show(int  a[][3]){ 
  for(int row = 0; row<2; row++) 
  { 
     for(int col=0; col<3; col++) 
     { 
        if( a[row][col] < 10){ cout << ’ ’; } 
        cout << a[row][col] << ’ ’; 
     } 
     cout << endl; 
} }
 0  1  2  
 3  4  5

[argarray.cpp] [margarray.cpp]