变量和基本类型

来源:互联网 发布:新疆干部网络培训学院 编辑:程序博客网 时间:2024/05/16 19:03

基本内置类型

2.1基本内置类型

2.1.1算术类型

代码日记:

//#include "stdafx.h"#include <iostream>using namespace std;/*基本内置类型分为算术类型(arithmetic type)和空类型(void)*///2.1.1算术类型void arithmetic_type(void){    /*#算术类型分为#    *integral type(字符型和布尔型也是整型)和浮点型    */    bool bool_example = true;//    cout << "bool:"<<sizeof(bool)<<"byte "<<bool_example<<endl;    char char_example = 'a';//字符,8位    cout << "char:" << sizeof(char) << "byte " << char_example << endl;    wchar_t wchar_t_example = 'a';//宽字符,至少16位    cout << "wchar_t" << sizeof(wchar_t) << "byte " << wchar_t_example << endl;    char16_t char16_t_example = 'a';//最少16位,使用Unicode字符集    cout << "char16_t:" << sizeof(char16_t) << "byte " << char16_t_example << endl;    char32_t char32_t_example = 'a';//最少32位,使用Unicode字符集    cout << "char32_t:" << sizeof(char32_t) << "byte " << char32_t_example << endl;    short short_example = 10;//最少16位    cout << "short:" << sizeof(short) << "byte " << short_example << endl;    int int_example = 10;//至少和short一样大,最小16位    cout << "int:" << sizeof(int) << "byte " << int_example << endl;    long long_example = 10;//至少和int一样大,最小32位    cout << "long:" << sizeof(long) << "byte " << long_example << endl;    long long long_long_example = 10;//至少和long一样大,最小64位    cout << "long long:" << sizeof(long long) << "byte " << long_long_example << endl;    float float_example = 10;//最小尺寸,6位有效数字    cout << "float:" << sizeof(float) << "byte " << float_example << endl;    double double_example = 10;//最小尺寸,10位有效数字    cout << "double:" << sizeof(double) << "byte " << double_example << endl;    long double long_double_example = 10;//最小尺寸,10位有效数字    cout << "long double:" << sizeof(long double) << "byte " << long_double_example << endl;}//2.1.2类型转换void type_convert(void){}int main(){    arithmetic_type();    system("pause");    return 0;}