CPSC 233 Lecture Notes - Lecture 7: Local Variable
Document Summary
Delimited by { } (eg. ) x = y * y; z = z / 2. 0; Local variables can be declared within a block. Allocated on stack memory when the block is entered. Scope is limited to the block of code (i. e. ) cannot be accessed from outside the block (eg. ) void myfunction() int i; if (i == 10) { General form: if (expression) statement; else statement; The expression must evaluate to true or false values. Can use an of the relational and logical operators to help from complex expressions. Use braces for more than one statement if (expression) { statement1; statement2; If-else-if ladders are common if (condition) statement; else if (condition2) statement2; else if (condition3;) statement3; else statement4n; (eg. ) if (a == b) else if (a < b) else. If statements can be nested (eg. ) if (x < 3) { if (y == 0) else. Switch (expression) { case constant1: statements; break; case constant2: statements; break; default: statements; break;