C++中编写函数实现交换两个字符型指针的值的功能
如下程序输出为teacherstudent,并没有实现交换功能,求问问题出在哪#include<iostream>usingnamespacestd;charSwapCh...
如下程序输出为 teacher student ,并没有实现交换功能,求问问题出在哪
#include<iostream>
using namespace std;
char SwapCharPionter(char *s1, char *s2)
{
char *s;
s = s1;
s1 = s2;
s2 = s;
return 0;
}
int main()
{
char s3[] = "teacher", s4[] = "student";
char *s1 = s3;
char *s2 = s4;
SwapCharPionter(s1, s2);
cout << s1 << endl;
cout << s2 << endl;
return 0;
} 展开
#include<iostream>
using namespace std;
char SwapCharPionter(char *s1, char *s2)
{
char *s;
s = s1;
s1 = s2;
s2 = s;
return 0;
}
int main()
{
char s3[] = "teacher", s4[] = "student";
char *s1 = s3;
char *s2 = s4;
SwapCharPionter(s1, s2);
cout << s1 << endl;
cout << s2 << endl;
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询