限定域基础知识(134) 发表于 2015-09-23 | 分类于 语言 结构填充++12345678910111213141516171819202122232425262728293031323334struct {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值。做个唯一的东东。。