当前位置:网站首页>C语言学习记录--变量基本类型和内存大小
C语言学习记录--变量基本类型和内存大小
2022-08-11 05:16:00 【FussyCat】
1、不同基本变量类型内存大小,按系统的编译位数32位和64位来区分,有区别的地方是类型long上,在32位编译器编译出来的是4个字节长度,而在64位编译器上编译出来的则是8个字节。
也有人是按LP32 ILP32 LP64 LLP64 ILP64 来分以上几个数据类型的字节长度的,可以参考:数据模型的解释参考
2、下面就实际看看以上的10种数据类型,验证表格中的字节长度是否准确。我的PC是64位的,有32位的朋友可以直接看看32位上的表现。
好吧,朋友们,原谅我不小心写成C++了,该死的Visual Studio,后面再补成C了,这个不影响字节长度计算的。
#include <iostream>
using namespace std;
int main()
{
char char_a = 'a';
char str[] = "\\\\";
char str1[] = "hello";
short short_i = 1;
int int_i = 1;
unsigned uint_i = 1;
long long_i = 1;
long long llong_i = 1;
unsigned long ulong_i = 1;
float float_i = 1.0;
double double_i = 1.0;
char getstr[] = {
0 };
cout << "Hello My C!\r\n";
cout << "char_a size:" << sizeof(char_a) << endl;
cout << "short_i size:" << sizeof(short_i) << ", int_i size:" << sizeof(int_i) << ", uint_i size:" << sizeof(uint_i) << endl;
cout << "long_i size:" << sizeof(long_i) << ", llong_i size:" << sizeof(llong_i) << ", ulong_i size:" << sizeof(ulong_i) << endl;
cout << "float_i size:" << sizeof(float_i) << ", double_i size:" << sizeof(double_i) << endl;
cout << "str size:" << sizeof(str) << ", str1 size:" << sizeof(str1) << endl;
cin >> getstr;
}
3、可以加上unsigned的有char short int long,其他的不可以。
哦,该睡觉了。。。明天又是漫长的上班时间。。。
边栏推荐
- Tips to improve your productivity, you have to know - Navitcat shortcuts
- The most complete installation tutorial of Pytorch (one step)
- QT QLabel控件(使用详解)
- 程序员小白的自我救赎之路。
- win下Anaconda(环境配置等)和pycharm安装详细教程
- Minecraft
- pytorch和tensorflow函数对应表
- Delphi7 learning record - demo example
- 【win10+cuda7.5+cudnn6.0安装caffe④】安装pycaffe
- 注解式编程小记
猜你喜欢
随机推荐
吃瓜教程task04 第5章 神经网络
QT QLabel控件(使用详解)
第6章 分支语句和逻辑运算符
【备忘】于仕琪的libfacedetection相关
性能效率测试
Visual Studio上一些Error的解决方案
第5章 循环和关系表达式
(3) Construction of a real-time performance monitoring platform (Grafana+Prometheus+Node_explorer+Jmeter)
IDEA使用记录
shell 脚本编程---入门
并发编程之线程基础
flaks framework learning: adding variables to the URL
task02 fashion-mnist分类实战
Flask框架学习:路由的尾部斜杠
Redis中RDB和AOF的区别
tensorflow代码翻译成pytorch代码 -详细教程+案例
开炮,开炮
全国青少年信息学奥林匹克联赛大纲
简单做份西红柿炒蛋778
【动态代理】CGLIB 动态代理的使用及原理