A few sections ago, I said that you can make up any name you want for
your variables, but that’s not quite true. There are certain words that
are reserved in C++ because they are used by the compiler to parse the
structure of your program, and if you use them as variable names, it
will get confused. These words, called keywords, include
endl and many more.
A list of C++ keywords is availiable publically on
cppreference. You can
take a look for yourself by pasting the following link into your browser.
Rather than memorize the list, I would suggest that you take advantage of a feature provided in many development environments: code highlighting. As you type, different parts of your program should appear in different colors. For example, keywords might be blue, strings red, and other code black.
If you type a variable name and it turns blue, watch out! You might get some strange behavior from the compiler.
Case matters! You can name a
String without an issue
because C++ does not consider
String to be the same as keyword
Also, a anything written in quotes, for example
"string" is not considered
a keyword in C++, even if it is spelt the same.
Fix the code below so that it runs without errors. Hint: you might need to change the names of some variables.