Exercise 6.21
1 intMax (constintX, constint*y)2 {3 if(X > *y)4 returnx;5 Else6 return*y;7 }8 9 intMain ()Ten { One inta1, A2; A while(CIN >> A1 >>A2) - { -cout <<"The Max is"<< Max (A1, &A2) <<Endl; the } -System"Pause"); - return 0; -}
const INT *
Exercise 6.22
1 voidChangeint**x,int**y)2 {3 int*temp;4temp = *y;5*y = *x;6*x =temp;7 }8 9 intMain ()Ten { One intA1 =Ten; A intA2 = -; - int*i = &A1; - int*j = &A2; theChange (&i, &j); -cout << *i <<" "<< *j <<Endl; -System"Pause"); - return 0; +}
Exercise 6.23
voidPrintint(&J) [2],intI//Int (&J) [2]{ for(i =0; I! =2; ++i) cout<<* (j+i) <<Endl;}voidPrint2 (int*p,inti) { for(i =0; I! =2; ++i) cout<< * (p+i) <<Endl;} intMain () {inti =0; intj[2] = {0,1}; //int a[10] = {1,2,3,4,5,6,7,8,9,10};cout <<"Calls Function:"<<Endl; Print (j,i); cout<<"Calls Function:"<<Endl; Print2 (J,i); return 0;}
Exercise 6.24
The right
1 voidPrintConst intia[Ten]) 2 {3 for(size_t i =0; I! =Ten; ++i)4cout << Ia[i] <<Endl;5 }6 7 intMain ()8 {9 Ten inta[Ten] = {1,2,3,4,5,6,7,8,9,Ten}; One print (a); A -System"Pause"); - return 0; the}
C + + Primer 6.2.4 Practice Answers