C函数数组元素初始化
初始化時(shí),可隨意指定初始化的元素或者元素的范圍。
附gnu c 手冊(cè)。
http://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html
代碼:
test.c
1 #include <stdio.h> 2 static const unsigned int boot_gdt[] __attribute__((aligned(16))) = { 3 [1] = 0x11223344, 4 [2] = 0x11223344, 5 [3 ... 10] = 0x32, 6 [15] = 0x11223344 7 }; 8 9 typedef struct { unsigned long int pte; } pte_t; 10 11 int main(void){ 12 int len = sizeof(boot_gdt)/sizeof(int) - 1; 13 printf("the len of boot_gdt is %d \n", len + 1); 14 for(int i = 0; i <= len; i++){ 15 printf("the %d data is 0x%x\n", i, boot_gdt[i]); 16 } 17 }http://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#Initializing-Arrays?
編譯:
$ gcc -o test test.c -std=c99
運(yùn)行:
$ ./test
the len of? boot_gdt is 16
the 0 data is 0x0
the 1 data is 0x11223344
the 2 data is 0x11223344
the 3 data is 0x32
the 4 data is 0x32
the 5 data is 0x32
the 6 data is 0x32
the 7 data is 0x32
the 8 data is 0x32
the 9 data is 0x32
the 10 data is 0x32
the 11 data is 0x0
the 12 data is 0x0
the 13 data is 0x0
the 14 data is 0x0
the 15 data is 0x11223344
?
轉(zhuǎn)載于:https://www.cnblogs.com/shaohef/p/3872909.html
超強(qiáng)干貨來襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生總結(jié)
以上是生活随笔為你收集整理的C函数数组元素初始化的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: padding与margin的差别
- 下一篇: 临时文档2