c++字節對齊問題測試

測試組1:


#include <iostream>
using namespace std;
int main()
{
	class test
	{
	public:
		int a;
		long long c;
		char b;		
	};
	cout << "size of test="<<sizeof(test) << endl;;

	class test1
	{
	public:
		int a;
		char b;
		long long c;
		
	};
	cout << "size of test1=" << sizeof(test1) << endl;;

	class test2
	{
	public:
		int a;
		long long c;
		char b;
		int d;
	};
	cout << "size of test2=" << sizeof(test2) << endl;;

	system("pause");
	return 0;
}

在這裏插入圖片描述


#include <iostream>

#pragma pack(push, 1) 
using namespace std;
int main()
{

	class test
	{
	public:
		int a;
		long long c;
		char b;		
	};
	cout << "size of test="<<sizeof(test) << endl;;

	class test1
	{
	public:
		int a;
		char b;
		long long c;
		
	};
	cout << "size of test1=" << sizeof(test1) << endl;;

	class test2
	{
	public:
		int a;
		long long c;
		char b;
		int d;
	};
	cout << "size of test2=" << sizeof(test2) << endl;;

	system("pause");
	return 0;
}

在這裏插入圖片描述


#include <iostream>


using namespace std;
int main()
{

	class test
	{
	public:
		int a;
		long long c;
		char b;		
		
	};
	cout << "size of test="<<sizeof(test) << endl;;

	class test1
	{
	public:
		int a;
		long long c;
		char b;
		int dasda(){
			return 0;
		};
		
	};


	cout << "size of test1=" << sizeof(test1) << endl;;

	class test2
	{
	public:
		int a;
		long long c;
		char b;
		virtual int dasddaa()=0;
	};
	cout << "size of test2=" << sizeof(test2) << endl;;

	system("pause");
	return 0;
}

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章