基本类型
这里所说的基本类型大致就是下面几种:
int
unsigned int
long int
long long
short int
char
float
double
对于这些类型所占字节数,其实并不是一定的。尤其是int
这个类型。
在32位编译器下和64位编译器下很可能是不同的。
下面是我在64位编译器下运行结果:
各位可以在自己机子下运行查看。
//
// main.cpp
// TypeBit
//
// Created by Alps on 15/4/1.
// Copyright (c) 2015年 chen. All rights reserved.
//
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
short int a = 0;
int b = 0;
unsigned int c = 0;
long int d = 0;
long long e = 0;
char f = 0;
float g = 0;
double h = 0;
printf("short int is: %lu byte\n",sizeof(a));
printf("int is : %lu byte\n",sizeof(b));
printf("unsigned int is: %lu byte\n",sizeof(c));
printf("long int is : %lu byte\n",sizeof(d));
printf("long long is : %lu byte\n",sizeof(e));
printf("char is : %lu byte\n",sizeof(f));
printf("float is : %lu byte\n",sizeof(g));
printf("double is : %lu byte\n",sizeof(h));
return 0;
}
其运行结果为:
short int is: 2 byte
int is : 4 byte
unsigned int is: 4 byte
long int is : 8 byte
long long is : 8 byte
char is : 1 byte
float is : 4 byte
double is : 8 byte
Program ended with exit code: 0
所以各位记得:char
是一个字节。而其他的都要看编译器和操作系统了。
对了~ 1个字节为8bit.