static的变量初值问题

 1 #include "iostream.h"
2
3 int i=1;
4
5 void others(void)
6 {
7 static int a;
8 static int b;
9 int c(3);
10 int i(2);
11 cout<<"i: "<<i<<"a: "<<a<<"b: "<<b<<"c: "<<c<<endl;
12 }
13
14 void main(void)
15 {
16 static int a;
17 int b=-10;
18 int c(0);
19 cout<<"i: "<<i<<"a: "<<a<<"b: "<<b<<"c: "<<c<<endl;
20 cout<<"\n"<<endl;
21 others();
22 }

同样的初值问题:在静态变量中,不论局部或是全局变量,只要确定 是static型,其初值无默认为0,如上例:

i: 1a: 0b: -10c: 0


i: 2a: 0b: 0c: 3
Press any key to continue

 

结果。

posted on 2012-03-31 13:57  Xilinx&Altera  阅读(358)  评论(0)    收藏  举报

导航