Navigation

Friday 13 September 2019

C++整数类型的范围如何看??


以下代码用来看电脑编译器,整数类型的范围。



#include <iostream>
#include "Sales_item.h"
int main() {
unsigned long long a;
a = 18446744073709551615;
std::cout << a + 1 << std::endl;
std::cout << "char contains " << sizeof(char) << "bytes" << std::endl;
std::cout << "unsigned char contains " << sizeof(unsigned char) << "bytes" << std::endl;
std::cout << "short contains " << sizeof(short) << "bytes" << std::endl;
std::cout << "unsigned short contains " << sizeof(unsigned short) << "bytes" << std::endl;
std::cout << "int contains " << sizeof(int) << "bytes" << std::endl;
std::cout << "unsigned contains " << sizeof(unsigned) << "bytes" << std::endl;
std::cout << "long contains " << sizeof(long) << "bytes" << std::endl;
std::cout << "unsigned long contains " << sizeof(unsigned long) << "bytes" << std::endl;
std::cout << "long long contains " << sizeof(long long) << "bytes" << std::endl;
std::cout << "unsigned long long contains " << sizeof(unsigned long long) << "bytes" << std::endl;
std::cout << "float " << sizeof(float) << "bytes" << std::endl;
std::cout << "double " << sizeof(double) << "bytes" << std::endl;
std::cout << "long double " << sizeof(long double) << "bytes" << std::endl;
getchar();
return 0;
}

No comments:

Post a Comment