What is a string literal?

I'm reading this book, and don't quite understand what it means when it is talking about string literals. It has this example code:
const char * bird = “wren”;

then talks about it some.........................................................................................

Then has this later on that page:
cout << “A concerned “ << bird << “ speaks\n”;

"String literals are constants, which is why the code uses the const keyword in the declaration.
Using const in this fashion means you can use bird to access the string but not to change it.
Chapter 7 takes up the topic of const pointers in greater detail. Finally, the pointer ps remains
uninitialized, so it doesn’t point to any string. (As you know, that is usually a bad idea, and
this example is no exception.)"
- From C++ Primer Plus (5th Edition)



I'm not understanding this paragraph, especially the first sentence about string literals.
"This is a string literal.";

A string literal is a bit of text between double quotes, as shown above. This quote has a type of const char *, which means several things.

(a) You cannot change it, but can access its value (const).
(b) A C++ compiler handles it much like it would a character array (char *).

Does this help somewhat?

-Albatross
A string literal is a bit of text between double quotes, as shown above. This quote has a type of const char *, which means several things.

(a) You cannot change it, but can access its value (const).
(b) A C++ compiler handles it much like it would a character array (char *).

Does this help somewhat?

-Albatross


Yes, that does help a lot. So they are talking about the "A concerned " and " speaks\n" when they say string literal, but not the bird pointer. Correct?
That's right!

-Albatross
Topic archived. No new replies allowed.