#include <stdio.h>
void reverse(char *str){
char * end = str;
char tmp;
if (str){
while(*end){
++end;
}
--end;
while (str < end){
tmp = *str;
*str++ = *end; // segmentation error
*end-- = tmp;
}
}
}
int main()
{
char *name = "erogol"
reverse(name);
//printf("%s\n", name );
return 0;
}
Why do you think segmentation error occurs at the place I singed with comment?