#include<iostream>
#include<cstdlib>
using
namespace std;
struct device
{
int num;
int count;
int reserve[0];//reserve是一个数组名;该数组没有元素;该数组的其实地址紧随结构题device之后;这种声明方法可以巧妙的实现C/C++语言里的数组扩展
};
int main()
{
struct device
*p_dev=(struct device*)malloc(sizeof(struct
device)+sizeof(int)*25);
//sizeof(int)*25是数组reserve的具体空间(25个元素)
p_dev->reserve[0]=99;
p_dev->reserve[24]=0;
cout<<"p_dev->reserve[0]="<<p_dev->reserve[0]<<endl;
cout<<"p_dev->reserve[24]="<<p_dev->reserve[24]<<endl;
cout<<"sizeof(struct device)="<<sizeof(struct
device)<<endl;
// 将结构体device之后的第一个内容(int值,其实就是reserve[0]的值)赋值给变量a
int a=*(&(p_dev->count)+1);
cout<<"a="<<a<<endl;
return
0;
}