admin管理员组

文章数量:1123010

c/c++基本类型sizeof:short,unsigned short,int,unsigned int,long,unsigned long,long long,unsigned long lon

  1. 类型字节表

 

 

 

 

X86

X86_64

short

signed short

short int

signed short int

2

2

unsigned short

 

 

unsigned short int

2

2

int

signed

signed int

 

4

4

unsigned int

unsigned

 

 

4

4

long

signed long

long int

signed long int

4

8

unsigned long

 

 

unsigned long int

4

8

long long

signed long long

long long int

signed long long int

8

8

unsigned long long

 

 

unsigned long long int

8

8

  1. 注意:

x86&x86_64

有char总为1字节

x86&x86_64

有short总为2字节

x86

有long long就是8字节

x86_64

有long就是8字节

  1. 例子

#include <iostream>

using namespace std;

 

int main(int argc, char* argv[])

{

    cout << "sizeof short:" << sizeof(short) << endl;

    cout << "sizeof unsigned short:" << sizeof(unsigned short) << endl;

    cout << "sizeof int:" << sizeof(int) << endl;

    cout << "sizeof unsigned int:" << sizeof(unsigned int) << endl;

    cout << "sizeof long:" << sizeof(long) << endl;

    cout << "sizeof unsigned long:" << sizeof(unsigned long) << endl;

    cout << "sizeof long long:" << sizeof(long long) << endl;

    cout << "sizeof unsigned long long:" << sizeof(unsigned long long) << endl;

    return 0;

}

本文标签: cc基本类型sizeofshortunsigned shortintunsigned intlong