基本信息
源码名称:C++字符串的交换
源码大小:0.43KB
文件格式:.cpp
开发语言:C/C++
更新时间:2019-11-26
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
自编函数实现两个字符串的交换。

#include <iostream>
using namespace std;

void  swap_int(int *a, int *b)
{
	int temp;
	temp = *b;
	*b = *a;
	*a= temp;
}
void swap_char( char **s1,  char **s2)
{
	char *s = NULL;
	s = *s2;
	*s2 = *s1;
        *s1 = s;
}	
int main()
{
	int a= 5, b=10;
	swap_int(&a,&b);
	cout<<"a="<<a<<"   b="<<b<<endl;
        char s1[10] = "abcd";
	char s2[10]= "haha";
	swap_char((char **)s1,(char **)s2);
	cout<<"s1="<<s1<<"  s2="<<s2<<endl;
	return 0;
}