Lecture 2

Definition informs the compiler that something exists

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: laration: Informs the compiler that something exists. • Definition: Informs the compiler that something exists and instructs the compiler to reserve space for it. Optionally, a definition of a variable may contain an initializer. 7 Named Constants • A constant cannot be changed at run time. • C style constants: • #define zero 0 • C++ style constants: • const int zero = 0; • const float PI = 3.14159; 9 TYPE Definitions • typedef float real • Now you can use the new term “real”. • If you need to deal with longer numbers you need to replace only one single statement. Otherwise you would need to replace every single place where you declared a variable to be float. 11 Examples • int x, y, z; • float volume; • int i = 0; • float test = 4.0; 8 Enumerations • enum {SU, MO, TU, WE, TH, FR, SA}; • enum Boolean {FALSE, TRUE}; • enum {plus = ‘ , minus = ‘ }; +’ -’ • enum {winter = 1, spring, summer, fall}; • enum {on, off} switch; 10 Arithmetic Expressions • +, -, *, /, % (binary) • +, - (unary) • Usual priority rules apply • Most operators are left associative...
View Full Document

Ask a homework question - tutors are online