Hi
Short answer: no
But I'll try to explain. Strings in C are confusing. It's usually better to think of them as an array of characters.
These lines are equivalent:
Code:
const char *str = "test";
const char str[5] = { 't','e','s','t','\0' };
Code:
char *str2 = (char*) str1;
This makes a new pointer variable called str2 and it points to str1 (the 't' character). If you try to modify that string, you will get a segmentation fault.
To make a new string that's a pointer to heap memory that you can modify and then free, use the strdup function.
Code:
char *str2 = strdup(str1);
The strdup allocates memory for the string with malloc, and then copies the string to that memory, and finally it returns a pointer to the new allocated memory.