-
Book Overview & Buying
-
Table Of Contents
Test-Driven Development with C++
By :
A string literal might look like a string, but the C++ compiler treats a string literal as a pointer to the first of a set of constant chars. The set of constant chars is terminated with a null character value, which is the numeric value of zero. That’s how the compiler knows how long the string is. It just keeps going until it finds the null. The reason that the chars are constant is that the data is normally stored in memory that is write protected, so it cannot be modified.
When we try to confirm a string literal, the compiler sees a pointer and has to decide which overloaded confirm function to call. Before we get too far with our exploration of string literals, what other problems can we get into with pointers?
Let’s start with the simple bool type and see what kinds of problems we run into if we try to confirm bool pointers. This will help you to understand string literal pointers by, first, understanding a simpler example test for...