当前位置:网站首页>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,其他的不可以。
哦,该睡觉了。。。明天又是漫长的上班时间。。。
边栏推荐
猜你喜欢
随机推荐
第二篇 DS5 Armv8 样例工程报错之GCC编译
task02 fashion-mnist分类实战
【win10+cuda7.5+cudnn6.0安装caffe①】安装cuda和cudnn
Delphi7 learning record - demo example
第8章 函数探幽-2
QT GrabWindow截取屏幕
UML基本概念——动态视图
Some common mysql entry exercises
Tips to improve your productivity, you have to know - Navitcat shortcuts
开炮,开炮
Flask framework learning: trailing slashes for routes
第10章 对象和类-2
第9章 内存模型和名称空间
Oracle常用语句归纳_持续更新
flask框架学习:debug与配置项
pytorch中tensor 生成的函数
pytorch基础之 pytorch 模型开发模板
博客目录管理 :机器学习 深度学习 nlp
判断一个字符串是否为空,如果为空,对其赋值,如果不为空,获取字符的个数并打印第一个字符
我的四核Cortex-A53学习之路