编制程序,调用传递引用的参数,实现两个字符串变量的交换.
例如:
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 on 2007-04-16 10:47 毁于随 阅读(79) 评论(0)  编辑 收藏 所属分类: C++ Primer学习

标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      


相关链接: