当前位置:网站首页>C language learning record--variable basic type and memory size

C language learning record--variable basic type and memory size

2022-08-11 05:45:00 FussyCat

1、The memory size of different basic variable types,Compilation bits by system32位和64bits to distinguish,Where there is a difference is the typelong上,在32Compiled by a bit compiler4个字节长度,而在64It is compiled on a bit compiler8个字节.
在这里插入图片描述
Some people are pressingLP32 ILP32 LP64 LLP64 ILP64 To divide the byte length of the above data types,可以参考:Interpretation reference for the data model

2、Let's take a look at the above actually10种数据类型,Verify that the byte length in the table is accurate.我的PC是64位的,有32Bit of friends can take a look directly32performance on the spot.
好吧,朋友们,Forgive me for accidentally writing itC++了,该死的Visual Studio,Refill laterC了,This does not affect the byte length calculation.

#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,其他的不可以.

哦,该睡觉了...Tomorrow is another long working day...

原网站

版权声明
本文为[FussyCat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110512507268.html