cpp 9.4

来源:互联网 发布:最新彩票预测软件 编辑:程序博客网 时间:2024/06/08 16:43

9.4

#include<iostream>void oil(int x);int main(){using namespace std;int texas = 31;int year = 2011;cout << "In main(), texas = " << texas << ", &texas = ";cout << &texas << endl;cout << "In main(), year = " << year << ", &year = ";cout << &year << endl;oil(texas);cout << "In main(), texas = " << texas << ", &texas = ";cout << &texas << endl;cout << "In main(),year = " << year << ", year = ";cout << &year << endl;system("pause");return 0;}void oil(int x){using namespace std;int texas = 5;cout << "In main(), texas = " << texas << ", &texas = ";cout << &texas << endl;cout << "In oil(), x = " << x << ", &x = ";cout << &x << endl;{int texas = 113;cout << "In block, texas = " << texas;cout << ", &texas = " << &texas << endl;cout << "In block, x = " << x << ", &x = ";cout << &x << endl;}cout << "Post-block texas = " << texas;cout << ", texas = " << &texas << endl;}

external.cpp

#include<iostream>using namespace std;double warming = 0.3;void update(double dt);void local();int main(){cout << "Global warming is " << warming << " degrees.\n";update(0.1);cout << "Global warming is " << warming << " degrees.\n";local();cout << "Global warming is " << warming << " degrees.\n";system("pause");return 0;}

support.exe

#include<iostream>extern double warming;void update(double dt);void local();using std::cout;void update(double dt){extern double warming;warming += dt;cout << "Updating global warming to " << warming;cout << " degrees.\n";}void local(){double warming = 0.8;cout << "Local warming = " << warming << " degrees.\n";cout << "But global warming = " << ::warming;cout << " degrees.\n";}


0 0
原创粉丝点击