C++数值范围 发表于 2017-04-17 | 分类于 C++ C++各数据类型的取值范围 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778#include<iostream>#include<string>#include <limits>using namespace std;int main(){ cout << "type: \t\t" << "************size**************"<< endl; cout << "bool: \t\t" << "所占字节数:" << sizeof(bool); cout << "\t最大值:" << (numeric_limits<bool>::max)(); cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl; cout << "char: \t\t" << "所占字节数:" << sizeof(char); cout << "\t最大值:" << (int)(numeric_limits<char>::max)(); cout << "\t\t最小值:" <<(int) (numeric_limits<char>::min)() << endl; cout << "signed char: \t" << "所占字节数:" << sizeof(signed char); cout << "\t最大值:" << (int)(numeric_limits<signed char>::max)(); cout << "\t\t最小值:" << (int)(numeric_limits<signed char>::min)() << endl; cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char); cout << "\t最大值:" << (int)(numeric_limits<unsigned char>::max)(); cout << "\t\t最小值:" << (int)(numeric_limits<unsigned char>::min)() << endl; cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t); cout << "\t最大值:" << (numeric_limits<wchar_t>::max)(); cout << "\t\t最小值:" << (numeric_limits<wchar_t>::min)() << endl; cout << "short: \t\t" << "所占字节数:" << sizeof(short); cout << "\t最大值:" << (numeric_limits<short>::max)(); cout << "\t\t最小值:" << (numeric_limits<short>::min)() << endl; cout << "int: \t\t" << "所占字节数:" << sizeof(int); cout << "\t最大值:" << (numeric_limits<int>::max)(); cout << "\t最小值:" << (numeric_limits<int>::min)() << endl; cout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned); cout << "\t最大值:" << (numeric_limits<unsigned>::max)(); cout << "\t最小值:" << (numeric_limits<unsigned>::min)() << endl; cout << "long: \t\t" << "所占字节数:" << sizeof(long); cout << "\t最大值:" << (numeric_limits<long>::max)(); cout << "\t最小值:" << (numeric_limits<long>::min)() << endl; cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long); cout << "\t最大值:" << (numeric_limits<unsigned long>::max)(); cout << "\t最小值:" << (numeric_limits<unsigned long>::min)() << endl; cout << "unsigned long long: \t" << "所占字节数:" << sizeof(unsigned long long); cout << "\t最大值:" << (numeric_limits<unsigned long long>::max)(); cout << "\t最小值:" << (numeric_limits<unsigned long long>::min)() << endl; cout << "double: \t" << "所占字节数:" << sizeof(double); cout << "\t最大值:" << (numeric_limits<double>::max)(); cout << "\t最小值:" << (numeric_limits<double>::min)() << endl; cout << "long double: \t" << "所占字节数:" << sizeof(long double); cout << "\t最大值:" << (numeric_limits<long double>::max)(); cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl; cout << "float: \t\t" << "所占字节数:" << sizeof(float); cout << "\t最大值:" << (numeric_limits<float>::max)(); cout << "\t最小值:" << (numeric_limits<float>::min)() << endl; cout << "size_t: \t" << "所占字节数:" << sizeof(size_t); cout << "\t最大值:" << (numeric_limits<size_t>::max)(); cout << "\t最小值:" << (numeric_limits<size_t>::min)() << endl; cout << "string: \t" << "所占字节数:" << sizeof(string) << endl; // << "\t最大值:" << (numeric_limits<string>::max)() << "\t最小值:" << (numeric_limits<string>::min)() << endl; cout << "type: \t\t" << "************size**************"<< endl; return 0;}type: ************size**************bool: 所占字节数:1 最大值:1 最小值:0char: 所占字节数:1 最大值:127 最小值:-128signed char: 所占字节数:1 最大值:127 最小值:-128unsigned char: 所占字节数:1 最大值:255 最小值:0wchar_t: 所占字节数:2 最大值:65535 最小值:0short: 所占字节数:2 最大值:32767 最小值:-32768int: 所占字节数:4 最大值:2147483647 最小值:-2147483648unsigned: 所占字节数:4 最大值:4294967295 最小值:0long: 所占字节数:4 最大值:2147483647 最小值:-2147483648unsigned long: 所占字节数:4 最大值:4294967295 最小值:0unsigned long long: 所占字节数:8 最大值:18446744073709551615 最小值:0double: 所占字节数:8 最大值:1.79769e+308 最小值:2.22507e-308long double: 所占字节数:16 最大值:1.18973e+4932 最小值:3.3621e-4932float: 所占字节数:4 最大值:3.40282e+038 最小值:1.17549e-038size_t: 所占字节数:8 最大值:18446744073709551615 最小值:0string: 所占字节数:8type: ************size************** $$f(x)=x^{x^x}$$ 123456789101112131415161718192021222324252627282930313233343536#include<stdio.h> #include<string.h>int main() { char c, s[20], *p; int a=1234, *i; float f=3.141592653589; double x=0.12345678987654321; p="How do you do"; strcpy(s, "Hello, Comrade"); *i=12; c='\x41'; printf("a=%d\n", a); /*结果输出十进制整数a=1234*/ printf("a=%6d\n", a); /*结果输出6位十进制数a= 1234*/ printf("a=%06d\n", a); /*结果输出6位十进制数a=001234*/ printf("a=%2d\n", a); /*a超过2位, 按实际值输出a=1234*/ printf("*i=%4d\n", *i); /*输出4位十进制整数*i= 12*/ printf("*i=%-4d\n", *i); /*输出左对齐4位十进制整数*i=12*/ printf("i=%p\n", i); /*输出地址i=06E4*/ printf("f=%f\n", f); /*输出浮点数f=3.141593*/ printf("f=6.4f\n", f); /*输出6位其中小数点后4位的浮点数 f=3.1416*/ printf("x=%lf\n", x); /*输出长浮点数x=0.123457*/ printf("x=%18.16lf\n", x);/*输出18位其中小数点后16位的长浮点 数x=0.1234567898765432*/ printf("c=%c\n", c); /*输出字符c=A*/ printf("c=%x\n", c); /*输出字符的ASCII码值c=41*/ printf("s[]=%s\n", s); /*输出数组字符串s[]=Hello, Comrade*/ printf("s[]=%6.9s\n", s);/*输出最多9个字符的字符串s[]=Hello, Co*/ printf("s=%p\n", s); /*输出数组字符串首字符地址s=FFBE*/ printf("*p=%s\n", p); /* 输出指针字符串p=How do you do*/ printf("p=%p\n", p); /*输出指针的值p=0194*/ getch(); retunr 0; //DA8A42849788} MAKEFILEMakeFile写法 Effective C++Effective C++四十条规则 C++对象模型深入探索C++对象模型 进程通信进程通信 Linux多线程Linux多线程 -------------本文结束 感谢您的阅读------------- 作者:GonewithGt有问题请 留言 或者私信我的 微博。 满分是10分的话,这篇文章你给几分 赏 微信打赏