C语言指针问题
#include <iostream>#include <cstring>
#include <stdio.h>
#include <malloc.h>
using namespace std;
void reverse3(char *s)
{
int len = strlen(s);
char *p = (char*)malloc(len);
strcpy(p, s);
p[1] = 's';
s = p;
cout << s << endl;
}
int main() {
char *s = new char[4];
s = "abc";
reverse3(s);
cout << s << endl;
return 0;
}
请问main函数的cout为什么输出abc而不是asc呢,应该如何让他输出asc呢,请用C语言,不要用string之类的东西,谢谢