有问题
#include<stdio.h>
#include<string.h>
void swap(char *x, char *y){
char temp = *x;
*x = *y;
*y = temp;
}
void main(){
char *str = "apple";
swap(str, str+4);
}
#include<stdio.h>
#include<string.h>
void swap(char *x, char *y){
char temp = *x;
*x = *y;
*y = temp;
}
int main()
{
char str[] = "apple";
swap(str, str+4);
printf("%s", str);
}
段错误,常量字符串是不可以修改的
改成 char str[] = "apple";就可以了