10 Static - Click to edit Master subtitle style Engineering 101 Static Variables Scope Lifetime Quote of the Day Confucius Our greatest glory is

This preview shows pages 1–10. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: Click to edit Master subtitle style Engineering 101 Static Variables / Scope / Lifetime Quote of the Day- Confucius Our greatest glory is not in never falling, but in getting up every time we do. Modifications to the n Usually when an identifier is declared the computer sets aside memory in which to store the associated data. n The memory is then available for use. It can be read and altered during the course of the program. n However, sometimes we may want to treat certain data specially. Constants n If you want a variable to never change in the context of the code you can define it to be a const const double speedoflight = 3e8; n Note that const does not replace the type, but rather it modifies the data type. Aliases (References) n We can declare a new variable that is a stand-in for an other variable. double v = 5.0; double & w = v; cout << w << endl; n The above code will print 5.0 because v and w are the same variable. Aliases (References) n We have already used such variables implicitly when we do pass-by-reference. n We can make a reference that is a const. That means that the reference version cannot be changed. double v=5.0; const double & w = v; v = v + 1.0; w = w + 1.0; n This can be useful for passing data without having What is output to the screen? int main() { int A = 10; int & B = A; B = 12; if (A == 10) B = 6; else B = 7; A = 5; 1 – 57 2 – 56 3 – 55 4 – None of the above Scope n Each identifier has a context in which it is meaningful. Outside that context it cannot be referred to or used. This context is called its scope . n Think of it like people in a room and only being able to talk to the people in the room. Scope n An identifier in a compound statement has local scope . It is in scope from the time it is declared to the end of the enclosing braces....
View Full Document

This note was uploaded on 04/07/2010 for the course ENGR engr 101 taught by Professor Rinenberg during the Spring '10 term at University of Michigan.

Page1 / 37

10 Static - Click to edit Master subtitle style Engineering 101 Static Variables Scope Lifetime Quote of the Day Confucius Our greatest glory is

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online