CTEC1335/2008F Constants --------- Variables that don't (and can't) vary. Use the "const" keyword. The compiler will prevent a constant's value from being modified (with a compile error). C/C++ Datatypes =============== char unsigned char 8 bit integer / character / ASCII value short unsigned short 16 bit integer / word int unsigned depends on CPU / operating system / compiler no smaller than short no larger than long on Intel 386, Windows XP, Visual C++ 2005, ints are 32 bits long unsigned long 32 bit integer (64 bit integer on 64-bit CPU/ O/S / Compiler) float 32 bit real number (IEEE format, 7 significant digits) double 64 bit real number (IEEE format, 15 significant digits) bool Boolean: true or false char * C-style string: array of characters with a null (zero) character at the end ("zero terminated string") string C++ string Declaring Constants =================== These are for values that will not change during the program, or during the programmer's lifetime. You can also use constants to prevent "magic numbers" -- i.e., numeric values that are hard-coded in your code. Constants are useful for maintainability -- if you use a constant more than once in your program, when you have to change it, you only need to change it at a single line (the line where the constant is declared). By definition, you must provide a value immediately -- because a constant's value cannot be changed later! const char SPACE = ' ' ; // ASCII value for space const int MAX_GRADE = 100 ; // maximum grade for this course const double PI = 3.14159265 ; // pi For strings, either a C-style string or C++ string is acceptable. String constants allow you to change your program's prompts, outputs or even to translate your program into a language other than English. const char * const GREETING = "Welcome to the machine!" ; const string MESSAGE = "The program completed successfully" ; ===