C++基础--struct的大小
2024-10-21 10:04:53
在修改别人的代码的过程中,发现很多人会把struct和struct的定义混淆,在这里主要是为了提醒自己Struct定义的规范性。
#include <stdio.h> struct x{
int a;
char b;
}; typedef struct g{
int a;
char b;
}G; int main()
{
int a;
char b;
int m = sizeof(a);
int n = sizeof(b);
printf("size of int is %d\n", m);
printf("size of char is %d\n", n);
int x = sizeof(x);
int y = sizeof(G);
printf("size of struct is %d\n", x);
printf("size of struct G is %d\n", y);
return 0;
}
运行的结果为:
在这里Struct G的大小为8是因为:字节对齐,说明Struct在默认情况下,就已经做了字节对齐。
最新文章
- RubyMine优化设置
- LR12.53—第6课:运行负载测试
- samba 最简单配置 共享
- [SAP ABAP开发技术总结]IDoc
- javascript读取本地文件
- Delphi获取当前系统时间(使用API函数GetSystemTime)
- unity 调用android函数
- 将项目(代码)从GitHub上克隆(下载)到本地仓库
- php 将图片转成base64
- Angular中ui-router实现路由嵌套案例
- 前端、数据库、Django简单的练习
- mysql学习之路_视图
- Linux内核系统体系概述
- 华为手机使用objectAnimation异常
- 【剑指offer】用两个栈实现队列
- python之旅:字符编码
- oracle中如何把结果集插入临时表中
- SP263 PERIOD - Period
- 【Android】Android 学习记录贴
- excel linux扩展
热门文章
- 集合之四:List接口
- reset.css(重置浏览器默认样式)
- Windows USB 编程
- 解决执行maven项目出现 SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”. error
- STM32的固件升级(RTT
- pycharm安装与使用
- execution(* *..BookManager.save(..))的解读
- Bash编程(4) 参数与变量
- 如何限制html标签input的长度
- 解决 Java 调用 Azure SDK 证书错误 javax.net.ssl.SSLHandshakeException