那个朋友还能帮我看看这段程序那里有问题的啊!

rfuture 2003-10-16 03:55:53
#include<iostream.h>

void swap(char& str1,char& str2)
{
char temp;
temp=str1;
str1=str2;
str2=temp;
}

void main()
{
char * ap="hello";
char * bp="how are you?";

cout<<"ap: "<<ap<<endl;
cout<<"bp: "<<bp<<endl;
swap(ap,bp);
cout<<"ap: "<<ap<<endl;
cout<<"bp: "<<bp<<endl;
}
...全文
25 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
蝎子i软件 2003-10-16
  • 打赏
  • 举报
回复
#include<iostream.h>
using namespace std;

void swap(char *&str1,char *&str2) //here
{
char *temp; //here
temp=str1;
str1=str2;
str2=temp;
}

void main()
{
char * ap="hello";
char * bp="how are you?";

cout<<"ap: "<<ap<<endl;
cout<<"bp: "<<bp<<endl;
swap(ap,bp);
cout<<"ap: "<<ap<<endl;
cout<<"bp: "<<bp<<endl;
}
liem 2003-10-16
  • 打赏
  • 举报
回复
void swap(char** a,char **b)
{
char *t=*a;
*a=*b;
*b=t;
}

调用:
swap(&ap,&bp);

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧