In "C++ Primer (Fifth edition)", it says:
The type of an integer literal depends on its value and notation. By default, decimal literals are signed whereas octal and hexadecimal literals can be either signed or unsigned types. A decimal literal has the smallest type of int, long, or long long in which the literal's value fits. Octal and hexadecimal literals have the smallest type of int, unsigned int, long, unsigned long, long long, or unsigned long long in which the literal's value fits.
Running the following code in Visual C++ 2015:
#include <iostream>
using namespace std;
void verify_type(int a) { cout << "int" << endl; }
void verify_type(long a) { cout << "long" << endl; }
void verify_type(long long a) { cout << "long long" << endl; }
void verify_type(unsigned int a) { cout << "unsigned int" << endl; }
void verify_type(unsigned long a) { cout << "unsigned long" << endl; }
void verify_type(unsigned long long a) { cout << "unsigned long long" << endl; }
int main()
{
cout << "The value of INT_MAX is " << INT_MAX << endl;
cout << "The value of INT_MIN is " << INT_MIN << endl;
verify_type(2147483648);
verify_type(0x80000000U);
verify_type(0x80000000);
system("pause");
return 0;
}
I get this:
The value of INT_MAX is 2147483647
The value of INT_MIN is -2147483648
unsigned long
unsigned int
unsigned int
I would expect that verify_type(2147483648) would be long long. Why do I get unsigned long?