How are string literals represented and implemented in C++?
According to the standard: "An ordinary string literal has type "array of n const char" and static storage duration." i.e. const char* IIRC, string literals are usually stored in read-only memory. What you get when you create a string literal in a program, is a constant character pointer which points to the first character of the string. "helloworld", for example, would be stored contiguously in read-only memory as 'h' 'e' 'l' 'l' 'o' 'w' 'o' 'r' 'l' 'd' '\0' A constant character pointer which points to the character 'h' is returned. The string is null-terminated (the end of the string is signified by the presence of the '\0' character at the end of the contiguous blocks.
string literals are long sequence of letters which are enclosed by double quote ( "") . Ex- " Hi I am James " ; all string literals are terminated by an escape sequence ' \0 ' (NULL) that's why the length of the string is 1 more than the letter it consists . string a = " Hi I am James " ; cout << a << endl; // Hi I am James
They are C-style strings (null-terminated).
Null termination also happens in c++ ( string ) they are literally added by \0 at the end