sizeof 是一个关键字,它是一个编译时运算符,用于判断变量或数据类型的字节大小。

sizeof 运算符可用于获取类、结构、共用体和其他用户自定义数据类型的大小。

使用 sizeof 的语法如下:

sizeof (data type)

其中,data type 是要计算大小的数据类型,包括类、结构、共用体和其他用户自定义数据类型。

请尝试下面的实例,理解 C++ 中 sizeof 的用法。复制并黏贴下面的 C++ 程序到 test.cpp 文件中,编译并运行程序。

 #include <iostream>
using namespace std; int main()
{
cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of short int : " << sizeof(short int) << endl;
cout << "Size of long int : " << sizeof(long int) << endl;
cout << "Size of float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl;
cout << "Size of wchar_t : " << sizeof(wchar_t) << endl;
return ;
}

当上面的代码被编译和执行时,它会产生下列结果,结果会根据使用的机器而不同:

 Size of char :
Size of int :
Size of short int :
Size of long int :
Size of float :
Size of double :
Size of wchar_t :

最新文章

  1. Web site collections
  2. 算法-QuickSort
  3. 如何让django方法自动地定期执行
  4. POJ 1836 Alignment
  5. Axis2在Web项目中整合Spring
  6. 9款经典华丽的CSS3分享按钮
  7. 函数buf_page_address_fold
  8. C#如何将线程中的代码抛到主线程去执行
  9. The version of CocoaPods used to generate the lockfile (*) is higher than the version of the current executable (*). Incompatibility issues may arise.
  10. java自学找工作经历
  11. 2D空间的OBB碰撞实现
  12. restfull环境搭建-helloword
  13. Linux 进程管理 ps、top、pstree命令
  14. Nginx的程序架构优化
  15. mybatis查询时间段sql语句
  16. 大规模网站sesson会话保持思路及实践配置
  17. POJ2115:C Looooops(一元线性同余方程)
  18. java的reflection
  19. DHCP(动态主机配置协议)工作流程
  20. Mybatis动态构建Sql(无实体类)

热门文章

  1. [CISCN 2019 初赛]Love Math
  2. jdk 的安装教程
  3. tensorflow之最近邻算法实现
  4. ES系列之Promise async 和 await
  5. UVA-101 The Blocks Problem 栈模拟
  6. 吴裕雄--天生自然MySQL学习笔记:MySQL 创建数据表
  7. 吴裕雄--天生自然 JAVASCRIPT开发学习:HTML DOM 元素 (节点)
  8. hadoop cmd
  9. 题解【[FJOI2018]所罗门王的宝藏】
  10. bfs--奇怪的电梯P1135