代码改变世界

Class,strict sizeof用法

  钟铧若岩  阅读(20)  评论(1编辑  收藏  举报

 

复制代码
 1 #include "iostream"
 2 using namespace std;
 3 
 4 class A{};
 5 class A2{char d,e;};
 6 struct B{};
 7 struct C{char b,c;};
 8 struct D{int x,y;};
 9 
10 int main()
11 {
12 
13     cout << "sizeof(A) = " << sizeof(A) <<endl; //1 空类的长度就是1
14     cout << "sizeof(A2) = " << sizeof(A2) <<endl;   //2 
15 
16     A *p1 = new A();
17     A p2;
18     A *p3;
19 
20     cout << "sizeof(p1) = " << sizeof(p1) << endl; //8
21     cout << "sizeof(p2) = " << sizeof(p2) << endl; //1
22     cout << "sizeof(p3) = " << sizeof(p3) << endl; //8
23 
24     cout << "sizeof(B) = " << sizeof(B) <<endl;//1
25     cout << "sizeof(C) = " << sizeof(C) <<endl;//2
26     cout << "sizeof(D) = " << sizeof(D) <<endl;//8
27 
28 
29 
30     cout << "hello world" << endl;
31     return 0;
32 }
复制代码

 

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
点击右上角即可分享
微信分享提示