数据类型

2019-01-23  本文已影响0人  chbeychevelle
#include "pch.h"
#include <iostream>
#include <climits>

using namespace std;
int main()
{
    bool bools = 1;
    cout << "=============bool===============" << endl;
    cout << "bool 判断整形 :" << bools << endl;
    cout << "bool类型的长度:" << sizeof(bool) << "bytes" << endl;

    char chars[] = "-127~128";
    unsigned char uchars[] = "0~255";
    cout << "=============char===============" << endl;
    cout << "char 字符整形 :" << chars << endl;
    cout << "char类型的长度:" << sizeof(char) << "bytes"<< endl;
    cout << "unsigned char 无符号字符整形 :" << uchars << endl;
    cout << "unsigned char类型的长度:" << sizeof(unsigned char) << "bytes" << endl;
    cout << "相当于bool类型*256" << endl;

    short shorts = SHRT_MAX;
    unsigned short ushorts = USHRT_MAX;
    cout << "=============short===============" << endl;
    cout << "short 短整形 :" << shorts << endl;
    cout << "short类型的长度:" << sizeof(short) << "bytes" << endl;
    cout << "unsigned short 无符号短整形 :" << ushorts << endl;
    cout << "unsigned short类型的长度:" << sizeof(unsigned short) << "bytes" << endl;
    cout << "相当于char类型的平方" << endl;

    int ints = INT_MAX;
    unsigned int uints = UINT_MAX;
    cout << "=============int===============" << endl;
    cout << "int 整形 :" << ints << endl;
    cout << "int类型的长度:" << sizeof(int) << "bytes" << endl;
    cout << "unsigned int 无符号整形 :" << uints << endl;
    cout << "unsigned int类型的长度:" << sizeof(unsigned int) << "bytes" << endl;
    cout << "相当于short类型的平方" << endl;

    long longs = LONG_MAX;
    unsigned long ulongs = ULONG_MAX;
    cout << "=============long==============="<< endl;
    cout << "long 长整形 :" << longs << endl;
    cout << "long类型的长度:" << sizeof(long) << "bytes" << endl;
    cout << "unsigned long 无符号长整形 :" << ulongs << endl;
    cout << "unsigned long类型的长度:" << sizeof(unsigned long) << "bytes" << endl;
    cout << "与int 相等" << endl;

    long long Tlongs = LLONG_MAX;
    unsigned long long uTlongs = ULLONG_MAX;
    cout << "=============long long===============" << endl;
    cout << "long long 长整形 :" << Tlongs << endl;
    cout << "long long 类型的长度:" << sizeof(long long) << "bytes" << endl;
    cout << "unsigned long long 无符号长整形 :" << uTlongs << endl;
    cout << "unsigned long long 类型的长度:" << sizeof(unsigned long long) << "bytes" << endl;
    cout << "相当于int 或者 long 的平方" << endl;

    float floats = FLT_MAX;
    cout << "=============float===============" << endl;
    cout << "float浮点型 :" << floats << endl;
    cout << "float类型的长度:" << sizeof(float) << "bytes" << endl;

    double doubles = DBL_MAX;
    cout << "=============float===============" << endl;
    cout << "double浮点型 :" << doubles << endl;
    cout << "double类型的长度:" << sizeof(double) << "bytes" << endl;

}

上一篇 下一篇

猜你喜欢

热点阅读