zoukankan      html  css  js  c++  java
  • [problem]C++各种类型

    刷LeetCode的时候经常要解决越界的问题,比如INT_MIN取绝对值就越界了,所以知道没种类型的最小值及最大值很有必要。

    long和int一般都是4字节,但是long在32位系统和64位系统不同,但我自己电脑64位win 8.1测试还是4个字节,可能和VS的设置也有关系。

    所以解决越界问题用long long代替int就OK了。

     1 #include<iostream>
     2 #include<string>
     3 #include <limits>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     cout << "type: 		" << "************size**************"<< endl;
     9     cout << "bool: 		" << "所占字节数:" << sizeof(bool);
    10     cout << "	最大值:" << (numeric_limits<bool>::max)();
    11     cout << "		最小值:" << (numeric_limits<bool>::min)() << endl;
    12     cout << "char: 		" << "所占字节数:" << sizeof(char);
    13     cout << "	最大值:" << (numeric_limits<char>::max)();
    14     cout << "		最小值:" << (numeric_limits<char>::min)() << endl;
    15     cout << "signed char: 	" << "所占字节数:" << sizeof(signed char);
    16     cout << "	最大值:" << (numeric_limits<signed char>::max)();
    17     cout << "		最小值:" << (numeric_limits<signed char>::min)() << endl;
    18     cout << "unsigned char: 	" << "所占字节数:" << sizeof(unsigned char);
    19     cout << "	最大值:" << (numeric_limits<unsigned char>::max)();
    20     cout << "		最小值:" << (numeric_limits<unsigned char>::min)() << endl;
    21     cout << "wchar_t: 	" << "所占字节数:" << sizeof(wchar_t);
    22     cout << "	最大值:" << (numeric_limits<wchar_t>::max)();
    23     cout << "		最小值:" << (numeric_limits<wchar_t>::min)() << endl;
    24     cout << "short: 		" << "所占字节数:" << sizeof(short);
    25     cout << "	最大值:" << (numeric_limits<short>::max)();
    26     cout << "		最小值:" << (numeric_limits<short>::min)() << endl;
    27     cout << "int: 		" << "所占字节数:" << sizeof(int);
    28     cout << "	最大值:" << (numeric_limits<int>::max)();
    29     cout << "	最小值:" << (numeric_limits<int>::min)() << endl;
    30     cout << "unsigned: 	" << "所占字节数:" << sizeof(unsigned);
    31     cout << "	最大值:" << (numeric_limits<unsigned>::max)();
    32     cout << "	最小值:" << (numeric_limits<unsigned>::min)() << endl;
    33     cout << "long: 		" << "所占字节数:" << sizeof(long);
    34     cout << "	最大值:" << (numeric_limits<long>::max)();
    35     cout << "	最小值:" << (numeric_limits<long>::min)() << endl;
    36     cout << "unsigned long: 	" << "所占字节数:" << sizeof(unsigned long);
    37     cout << "	最大值:" << (numeric_limits<unsigned long>::max)();
    38     cout << "	最小值:" << (numeric_limits<unsigned long>::min)() << endl;
    39     cout << "double: 	" << "所占字节数:" << sizeof(double);
    40     cout << "	最大值:" << (numeric_limits<double>::max)();
    41     cout << "	最小值:" << (numeric_limits<double>::min)() << endl;
    42     cout << "long double: 	" << "所占字节数:" << sizeof(long double);
    43     cout << "	最大值:" << (numeric_limits<long double>::max)();
    44     cout << "	最小值:" << (numeric_limits<long double>::min)() << endl;
    45     cout << "float: 		" << "所占字节数:" << sizeof(float);
    46     cout << "	最大值:" << (numeric_limits<float>::max)();
    47     cout << "	最小值:" << (numeric_limits<float>::min)() << endl;
    48     cout << "size_t: 	" << "所占字节数:" << sizeof(size_t);
    49     cout << "	最大值:" << (numeric_limits<size_t>::max)();
    50     cout << "	最小值:" << (numeric_limits<size_t>::min)() << endl;
    51     cout << "string: 	" << "所占字节数:" << sizeof(string) << endl;
    52     cout << "type: 		" << "************size**************"<< endl;
    53     return 0;
    54 }

  • 相关阅读:
    这篇通俗实用的Vlookup函数教程,5分钟就可以包你一学就会
    nginx 常见正则匹配符号表示
    Nginx if 条件判断
    nginx 将请求全部指向到一个页面
    windows10下面部署nginx(解决文件名中文乱码问题)
    二.Nginx反向代理和静态资源服务配置
    Nginx的使用(一)代理静态文件
    使用Nginx反向代理和内容替换模块实现网页内容动态替换功能
    如何让NGINX显示文件夹目录
    Nginx 如何设置反向代理 多服务器,配置区分开来,单独文件保存单个服务器 server 主机名配置,通过 include 实现
  • 原文地址:https://www.cnblogs.com/Sean-le/p/4736880.html
Copyright © 2011-2022 走看看