[C++关键字] 内置类型

bool, char, short, char16_t (C++11), int, char32_t (C++11), float, long, double,在64位机器上测试各种类型的大小,代码如下

#include <iostream>
using namespace std;

#define P(A) cout<<"Size of " #A<<": "<<sizeof(A)<<endl;

int main()
{
    P(bool);
    P(char);
    P(short);
    P(char16_t);
    P(int);
    P(char32_t);
    P(float);
    P(long);
    P(double);
    return 1;
}

测试结果为

Size of bool: 1
Size of char: 1
Size of short: 2
Size of char16_t: 2
Size of int: 4
Size of char32_t: 4
Size of float: 4
Size of long: 8
Size of double: 8

 

posted @ 2016-03-14 00:04  CarlGoodman  阅读(206)  评论(0编辑  收藏  举报