因此,當我偶然發現一些「問題」(例如來自C++ Primer第6版)時,我正在使用新數據類型long long進行一些測試。我正在使用爬庫來告訴我長和長長支持的最大數量,並且都出來了9223372036854775807.這怎麼可能?爲什麼數據類型長期支持等於long long的最大數量?
#include <iostream>
#include <climits>
int main()
{
std::cout << "int size is " << sizeof(int) << " bytes." << std::endl;
std::cout << "short size is " << sizeof(short) << " bytes." << std::endl;
std::cout << "long size is " << sizeof(long) << " bytes." << std::endl;
std::cout << "long long size is " << sizeof(long long) << " bytes." << std::endl;
std::cout << "Maximum values: " << std::endl;
std::cout << "int: " << INT_MAX << std::endl;
std::cout << "short: " << SHRT_MAX << std::endl;
std::cout << "long: " << LONG_MAX << std::endl;
std::cout << "long long: " << LLONG_MAX << std::endl;
return 0;
}
參見每種數據類型所要求的最小* *尺寸這樣一個問題:http://stackoverflow.com/questions/589575/size-of-int-long-etc,注那它是所需的最小尺寸,即數據類型可以大於指定值。 – Naveen 2012-04-18 06:17:41