【面试】【编程基础】内存对齐

设struct {

short a;

char b;

float c;

}cs;

则sizeof(cs)的值是()


#include <iostream>
#include <stddef.h>

//#pragma pack(1)

using namespace std;

struct st_test{
	short a;
	char b;
	float c;
}test;

int main()
{
	cout << "sizeof(short)" << sizeof(short) << endl;
	cout << "sizeof(char)" << sizeof(char) << endl;
	cout << "sizeof(float)" << sizeof(float) << endl;

	cout << sizeof(test) << endl;


	cout << offsetof(st_test, a) << offsetof(st_test, b) << offsetof(st_test, c) << endl;

	cout << "0x" << (int*)&test << endl;



	return 0;
}




猜你喜欢

转载自blog.csdn.net/zamely/article/details/80690951
今日推荐