linux 内核源代码分析

  

  #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 
" ,sizeof(int));
		printf("char is %d
",sizeof(char));
		printf("float is %d
",sizeof(float));
		printf("devs is %d 
",sizeof(devs));
		printf("devs[0] is %d
",sizeof(devs[0]));
		printf("num is %d 
",sizeof(devs)/sizeof(devs[0]));
		return 0;	
}

实践结果例如以下:

原文地址:https://www.cnblogs.com/hrhguanli/p/3876093.html