Determine the scope of each of the variables in Example 20.7.
Be the computer and predict the output of the program.
[ fromfile: scopestorage.xml id: None ]
Example 20.7. src/early-examples/scopex.cpp
#include <iostream> using namespace std; long x = 17; float y = 7.3;static int z = 11;
class Thing { int m_Num;
public: static int s_Count;
Thing(int n = 0) : m_Num(n) {++s_Count;} ~Thing() {--s_Count;} int getNum() { return m_Num; } }; int Thing::s_Count = 0; Thing t(11); int fn(char c, int x) {
int z = 5;
double y = 6.933; { char y;
Thing z(4);
y = c + 3; ::y += 0.3;
cout << y << endl;
} cout << Thing::s_Count << endl;
y /= 3.0;
::z++;
cout << y << endl; return x + z; } int main() { int x, y = 10; char ch = 'B';
x = fn(ch, y); cout << x << endl; cout << ::y << endl;
cout << ::x / 2 << endl; cout << ::z << endl; }
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
|
Scope: ________________ |
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |