经典重现:
#include <stdio.h>
#include <malloc.h>
#include <string.h>
int main()
{
char *str = "hello,world.";
int len = strlen(str);
char *des = (char *)malloc(len+1);
char *s = &str[len-1];
char *d = des;
while(len--!=0)
{
*d++ = *s--;
}
*d = 0;
printf("%s\n",des);
free(des);
return 0;
}
char *str = "hello,world."; 实为:const char *str = "hello,world." ,只能查看,不能对数组操作。char *des = (char *)malloc(len+1),在堆里分配len+1。对其操作时:要另外申请一个指针去操作。