#include <stdio.h>
#include <string.h>
#define PRINT_D(intValue) printf(#intValue" is %d\n", (intValue));
#define OFFSET(struct,member) ((char *)&((struct *)0)->member - (char *)0)
#pragma pack(1)
typedef struct
{
char sex;
short score;
int age;
}student;
int main()
{
PRINT_D(sizeof(student))
PRINT_D(OFFSET(student,sex))
PRINT_D(OFFSET(student,score))
PRINT_D(OFFSET(student,age))
return 0;
}
sizeof(student) is 7 OFFSET(student,sex) is 0 OFFSET(student,score) is 1 OFFSET(student,age) is 3
#include <stdio.h>
#include <string.h>
#define PRINT_D(intValue) printf(#intValue" is %d\n", (intValue));
#define OFFSET(struct,member) ((char *)&((struct *)0)->member - (char *)0)
typedef struct
{
char sex;
short score;
int age;
}student;
int main()
{
PRINT_D(sizeof(student))
PRINT_D(OFFSET(student,sex))
PRINT_D(OFFSET(student,score))
PRINT_D(OFFSET(student,age))
return 0;
}
sizeof(student) is 8 OFFSET(student,sex) is 0 OFFSET(student,score) is 2 OFFSET(student,age) is 4
#include <stdio.h>
#include <string.h>
#define PRINT_D(intValue) printf(#intValue" is %d\n", (intValue));
#define OFFSET(struct, member) ((char *)&((struct *)0)->member - (char *)0)
#pragma pack(4)
typedef struct
{
char sex;
short score;
int age;
}student;
int main()
{
PRINT_D(sizeof(student))
PRINT_D(OFFSET(student,sex))
PRINT_D(OFFSET(student,score))
PRINT_D(OFFSET(student,age))
return 0;
}
sizeof(student) is 8 OFFSET(student,sex) is 0 OFFSET(student,score) is 2 OFFSET(student,age) is 4
#include <stdio.h>
#include <string.h>
#define PRINT_D(intValue) printf(#intValue" is %d\n", (intValue));
#define OFFSET(struct, member) ((char *)&((struct *)0)->member - (char *)0)
typedef struct
{
int a : 1;
int b : 3;
int : 0;
int d : 2;
}bit_info;
int main()
{
PRINT_D(sizeof(bit_info))
return 0;
}
sizeof(bit_info) is 8
struct A{
char f1 : 3;
char f2 : 4;
char f3 : 5;
};
struct B{
char f1 : 3;
short f2 : 4;
char f3 : 5;
};
struct C{
char f1 : 3;
char f2;
char f3 : 5;
};
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有