CSCI 10 Lecture Notes - Lecture 10: Local Variable
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).