CPSC 233 Lecture Notes - Lecture 7: Local Variable

33 views5 pages

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;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers