钱能C++习题9.3

编制程序,调用传递引用的参数,实现两个字符串变量的交换.
例如:
ap:"how are you?"
bp:"hello"

#include "stdafx.h"
#include 
<iostream>
#include 
<iomanip>
#include 
<math.h>


using namespace std;

void swapstring(char * & r1,char * & r2)
{
    
char * tmp=r1;
    r1
=r2;
    r2
=tmp;
}


int _tmain(int argc, _TCHAR* argv[])
{
    
char * ap="hello";
    
char * bp="how are you?";
    cout
<<ap<<","<<bp<<endl;
    swapstring(ap,bp);
    cout
<<ap<<","<<bp<<endl;

    
int i;
    cin
>>i;
    
return 0;
}

这道题应该考核的只是对指针的引用的学习.
char *是char型的指针,char * & r1则是对char * 指针的引用.
posted @ 2007-04-16 10:47  吴东雷  阅读(531)  评论(0)    收藏  举报