限定域基础知识(134)

结构填充++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
struct {int a; int b; int c;} d{1,2};
int b[10] = {1,2};
//默认填充用的是0,所以剩下的全是0;
**sizeof数组**
char p[] = "asdf";sizeof(p);结果是5,要多个空的结尾符号。
**static重复**
static int d = 1;
for (int i = 0; i < 2; i++) {
static int d = 12;
d += i;
}
cout << d;
// d的结果是1,可以看出和限定域有关。。。
static int d = 4;
{
int d = 3;
cout << d;
}
cout <<d;//一样的道理, 限定域的限制,结果不同;
void fun() {
static int number = 0;
if (0 == number++) {
cout << "ok";
}
}//一样和限定域有关,number虽是个static,但只能让fun访问。也正因为是static,所以每次遍历一定会++number值。做个唯一的东东。。
// //