Home > Articles

  • Print
  • + Share This
This chapter is from the book


Now that you've had the chance to try variables and constants, you can answer a few questions and do a couple of exercises to firm up your knowledge of the compiler.


  1. Why would you use unsigned over signed integers?

  2. What is the difference between initialization and defining a variable?

  3. Are the variables DOG, dog, Dog, and doG the same?

  4. What is the difference between a #define constant and const?


  1. Expand the program in Listing 3.1 to include all the variable types shown in Table 3.1. Your values may be the same or differ from those shown.

  2. Think about some of the numbers and information you see around you in daily life—and the type of variable that would be best to hold them. Think of meaningful variable names for them.

  3. If you have access to professional software developers, ask them their preferred variable naming format. If you have access to several of them, you will find that they have different approaches. Ask them "why?" You may be surprised at the answers you get.

Quiz Answers

  1. Unsigned integers allow you to count more positive values than signed. They will also not take any negative values. It is up to you as a programmer to determine which is best for the problem you are trying to solve.

  2. Definition is when you declare the data type and name of a variable. Initialization is the assignment of the first (or initial) value to it. Both definition and initialization can take place in the same command.

  3. No, they are not. C++ is case sensitive and each spelling looks like a different variable to the compiler. It is a matter of personal or group choice what form the names should take.

  4. The preprocessor directive #define substitutes the specified value (literal constant) into your code every place it is used. A variable declared to be const occupies one location and has the specified data type.

  • + Share This
  • 🔖 Save To Your Account