zoukankan      html  css  js  c++  java
  • C++:数据类型

    /**
     * C++ 数据类型 : https://www.runoob.com/cplusplus/cpp-data-types.html
     * 
     * 布尔: bool
     * 字符: char  1 个字节   -128 到 127 或者 0 到 255
     *       unsigned char  1 个字节   0 到 255
     *       signed char 1 个字节   -128 到 127 
     * 整型: int  4个字节 	-2147483648 到 2147483647
     *       unsigned int 4 个字节  0 到 4294967295
     *       signed int 4个字节  -2147483648 到 2147483647
     * 
     *       short int 2 个字节  -32768 到 32767
     *       unsigned short int	 2个字节 0 到 65,535
     *       signed short int	2个字节  -32768 到 32767
     * 
     *       long int	8 个字节 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807
     *       signed long int	8个字节  -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807
     *       unsigned long int	8个字节 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807
     *       
     * 浮点型: float 4 个字节   精度型占4个字节(32位)内存空间,+/- 3.4e +/- 38 (~7 个数字)
     * 双浮点: double   8个字节 双精度型占8 个字节(64位)内存空间,+/- 1.7e +/- 308 (~15 个数字)
     *        long double 16 个字节 长双精度型 16 个字节(128位)内存空间,可提供18-19位有效数字。
     * 无类型: void
     * 宽字符: wchar_t  2 或 4 个字节	1 个宽字符
    
    */ 
    
    #include <iostream>
    #include <limits>
    
    using namespace std;
    
    int main(){
        cout << "type: 		" << "*******size********" << endl;  // endl 换行
        // cout << "bool: 		" << "所占字节数: " << sizeof(bool) << endl;  // sizeof 获取数据类型的大小
        // cout << "	最大值:" << (numeric_limits<bool>::max)();  // (numeric_limits<bool>::max)() 获取数据类型的最大值
        // cout << "	最小值: " << (numeric_limits<bool>::min)() << endl;  // (numeric_limits<bool>::max)() 获取数据类型的最小值
    
        // // char
        // cout << "char: 		" << "所占字节数: " << sizeof(char) << endl;  // sizeof 获取数据类型的大小
        // cout << "	最大值:" << (numeric_limits<char>::max)();  // (numeric_limits<bool>::max)() 获取数据类型的最大值
        // cout << "	最小值: " << (numeric_limits<char>::min)() << endl;  // (numeric_limits<bool>::max)() 获取数据类型的最小值
    
        // //  signed char
        // cout << "signed char: 		" << "所占字节数: " << sizeof(signed char) << endl;  // sizeof 获取数据类型的大小
        // cout << "	最大值:" << (numeric_limits<signed char>::max)();  // (numeric_limits<bool>::max)() 获取数据类型的最大值
        // cout << "	最小值: " << (numeric_limits<signed char>::min)() << endl;  // (numeric_limits<bool>::max)() 获取数据类型的最小值
    
        // // unsigned char
        // cout << "unisgned char: 		" << "所占字节数: " << sizeof(unsigned char) << endl;
        // cout << "	最大值: " << (numeric_limits<unsigned char>::max)();
        // cout << "	最小值: " << (numeric_limits<unsigned char>::min)() << endl;
    
        // wchar_t
        cout << "wchar_t: 		" << "所占字节数: " << sizeof(wchar_t) << endl;
        cout << "	最大值: " << (numeric_limits<wchar_t>::max)();
        cout << "	最小值: " << (numeric_limits<wchar_t>::min)() << endl;
    
        // short
        cout << "short: 		" << "所占字节数: " << sizeof(short) << endl;
        cout << "	最大值: " << (numeric_limits<short>::max)();
        cout << "	最小值: " << (numeric_limits<short>::min)() << endl;
    
        // int
        cout << "int: 		" << "所占字节数: " << sizeof(int) << endl;
        cout << "	最大值: " << (numeric_limits<int>::max)();
        cout << "	最小值: " << (numeric_limits<int>::min)() << endl;
    
        // size_t
        cout << "size_t: 		" << "所占字节数: " << sizeof(size_t) << endl;
        cout << "	最大值: " << (numeric_limits<size_t>::max)();
        cout << "	最小值: " << (numeric_limits<size_t>::min)() << endl;
    
        // typedef : 为存在的 类型换个新名字
        typedef int number; // typedef 已有类型 新名称;
        number age;  // 声明 number 类型 的变量 age 
        age = 18;
        //  typeid(age).name() 获取变量的数据类型
        cout << "age: " << age  << "类型: " << typeid(age).name() << endl;
    
        // 枚举类型 enum
        enum User{
            name,
            age1
        } user;
        user = name;
        cout << "user: " << user << endl;
        return 0;
    }
    
    作者:zy7y
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    DataTable四个方法
    c++面向对象编程必备“良方”(转)
    函数调用约定
    AFX_IDW_PANE_FIRST(转)
    CString.Format的详细用法(转)
    ID的分配 (转)
    CString用法整理(转载)
    jquery之效果
    JS 水仙数
    CSS 文本换行
  • 原文地址:https://www.cnblogs.com/zy7y/p/14801543.html
Copyright © 2011-2022 走看看