linux 内核源码分析 - 获取数组的大小
时间:2014-05-09 02:10:16
收藏:0
阅读:494
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
测试程序:
#include<stdio.h> #include<stdlib.h> struct dev { int a; char b; float c; }; struct dev devs[]= { { 1,‘a‘,7.0, }, { 1,‘a‘,7.0, }, { 1,‘a‘,7.0, }, }; int main() { printf("int is %d \n" ,sizeof(int)); printf("char is %d\n",sizeof(char)); printf("float is %d\n",sizeof(float)); printf("devs is %d \n",sizeof(devs)); printf("devs[0] is %d\n",sizeof(devs[0])); printf("num is %d \n",sizeof(devs)/sizeof(devs[0])); return 0; }
实践结果如下:
评论(0)