静态持续变量、内部链接性

来源:互联网 发布:web前端开发 薪资知乎 编辑:程序博客网 时间:2024/06/06 15:53

将static限定符用于作用域为整个文件的变量时,该变量的链接性是内部的即只能在所属的文件中使用它。为了区分具有外部链接性的外部变量和用static限定的内部链接性的变量,以下程序做了示例:

//Main.cpp#include <iostream>using namespace std;double warming=0.1;//定义外部变量int i=1;static int j=2;void remote();int main(){    cout<<"main( ) reports the following address:\n ";    cout<<&warming<<"=&warming ,"<<&i<<"=&i,"<<&j<<"=&j\n";    remote();    return 0;} 
#include <iostream>using namespace std;extern double warming;//引用定义的外部变量warming;static int i=3;//内部链接性的iint j=4;//外部变量chvoid remote(){    cout<<"remote( ) reports the following address:\n ";    cout<<&warming<<"=&warming ,"<<&i<<"=&i,"<<&j<<"=&j\n";}

输出结果:
这里写图片描述

阅读全文
0 0