- What Is a Variable?
- Common Compiler-Supported C++ Variable Types
- Determining the Size of a Variable Using sizeof
- Automatic Type Inference Using auto
- Using typedef to Substitute a Variable's Type
- What Is a Constant?
- Keywords You Cannot Use as Variable or Constant Names
- Summary
- Q&A
- Workshop
Keywords You Cannot Use as Variable or Constant Names
Some words are reserved by C++, and you cannot use them as variable names. These keywords have special meaning to the C++ compiler. Keywords include if, while, for, and main. A list of keywords defined by C++ is presented in Table 3.2 as well as in Appendix B, “C++ Keywords.” Your compiler might have additional reserved words, so you should check its manual for a complete list.
TABLE 3.2 Major C++ Keywords
asm |
else |
new |
this |
auto |
enum |
operator |
throw |
bool |
explicit |
private |
true |
break |
export |
protected |
try |
case |
extern |
public |
typedef |
catch |
false |
register |
typeid |
char |
float |
reinterpret_cast |
typename |
class |
for |
return |
union |
const |
friend |
short |
unsigned |
constexpr |
goto |
signed |
using |
continue |
if |
sizeof |
virtual |
default |
inline |
static |
void |
delete |
int |
static_cast |
volatile |
do |
long |
struct |
wchar_t |
double |
mutable |
switch |
while |
dynamic_cast |
namespace |
template |
|
In addition, the following words are reserved: |
|||
and |
bitor |
not_eq |
xor |
and_eq |
compl |
or |
xor_eq |
bitand |
not |
or_eq |
|