CSCI 10 Lecture Notes - Lecture 10: Local Variable

46 views3 pages

Document Summary

In computer programming, the scope of a name binding, such as a variable, is the part of a computer program where the binding is valid: where the name can be used to refer to the entity. #include using namespace std; int area(int w, int h); int main () { int w; cout << (cid:498)w = (cid:498); cin >> w; int h; return 0; int area (int w, int h) { return w * h; Variables declared in a function are local to that function. The binding of a local variable is only valid to that function. The only way to get data out of the function is to return it! Even if local variables have the same name, they don"t interfere with each other. Local variables are stored in different spaces in ram. Call-by-value: when called, a variable is copied over to the function. After the return statement, the variables will be no longer accessible(random data leftover).

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

Related Documents