3a-c++ primer基本内置类型
#include <iostream> #include <windows.h> int main() { short sh; unsigned short sh1; sh = 100000; sh1 = 100000; std::cout << "short类型的sh的值是: " << sh << std::endl; std::cout << "unsigned short类型的sh1的值是: " << sh1 << std::endl; //100000大于65535的存储范围,溢出了。所以100000%65536=34464 std::cout << "ungined没有short的size是: " << sizeof(signed) << "为" << sizeof(signed) * 8 << "位" << std::endl; std::cout << "int的size是: " << sizeof(int) << "为" << sizeof(int) * 8 << "位" << std::endl; std::cout << "char的size是: " << sizeof(char) << "为" << sizeof(char) * 8 << "位" << std::endl; std::cout << "wchar_t的size是: " << sizeof(wchar_t) << "为" << sizeof(wchar_t) * 8 << "位" << std::endl; std::cout << "bool的size是: " << sizeof(bool) << "为" << sizeof(bool) * 8 << "位" << std::endl; std::cout << "float的size是: " << sizeof(float) << "为" << sizeof(float) * 8 << "位" << std::endl; std::cout << "double的size是: " << sizeof(double) << "为" << sizeof(double) * 8 << "位" << std::endl; Sleep(500000); //short 16位 有一个符号位:所以是-2的15次方(-32768)~+32767。 //unsigned short 16位 无符号0-65535 //unsigned 32位 //int 32位 //char 8位 //wchar_t 16位 //bool 8位 //float 32 //double 64 return 0; }