In C, there is two ways to define a string:
- Define it as an array of character such as:
char aname[] = "Imad";- The array would be of size number of characters plus 1 for the null terminating character.
- Or define it as a pointer to string constant such as:
char *pname = "Imad";They are almost identical except for 1 subtle difference:
anamewill always point to the same storage and can’t be changed to point to something else. The characters themselves can be changed.pnameis a pointer so it can be changed to point to something else. If we try to modify the underlying characters, we get an error because the string is stored in.rodatawhich can’t be modified at runtime.