Jun 18, 2013 at 1:19pm
Hey Everyone,
I understand that strings are objects of the class string, so when you store a string in a variable, it's actually a reference to the string object.
But where is the string literal being stored?
I feel like I'm missing something essential to understanding this...
Jun 18, 2013 at 1:23pm
String literals if they do not used to initialize a character array are stored in static memory. For example
char s[] = "String Literal";
Here the string literal is not stored in the program. It is used only to initialize the array.
const char *s = "String Literal";
Here the string literal is stored in static memory of the program and has type const char[15].
Last edited on Jun 18, 2013 at 4:35pm
Jun 18, 2013 at 1:52pm
Great explanation.
Thanks vlad!
Jun 18, 2013 at 3:03pm
all string literals are stored in static memory (although compilers are permitted to optimize them out when possible)
Last edited on Jun 18, 2013 at 3:14pm