Workshop
Now that you've learned about variables and constants, you can answer a few questions and do a couple of exercises to firm up your knowledge about them.
Quiz
-
Why would you use unsigned over signed integers?
- They hold more numbers.
- They hold more positive numbers.
- There's no reason to prefer one over the other.
-
Are the variables ROSE, rose, and Rose the same?
- Yes
- No
- None of your business
-
What is the difference between a #define constant and const?
- Only one is handled by the preprocessor.
- Only one has a type.
- Both a and b
Answers
-
B. Unsigned integers hold more positive values and cannot be used to hold negative values. They hold the same number of values.
-
B. Because C++ is case sensitive, a ROSE is not a rose is not a Rose. Each reference is treated as a different variable by the compiler.
-
C. The preprocessor directive #define substitutes the specified value into your code every place it appears in code. It does not have a data type and is invisible to the compiler. A constant, created with the keyword const, has a data type and is handled by the compiler.