/* DemoDatatypes1.cpp CIS 150 5/29/2008 David Klick This program shows the range of the basic integer data types. The output will differ depending on what compiler is used. */ #include #include using std::cin; using std::cout; using std::endl; void cont(); int main(void) { // declare and initialize variables short minShort = SHRT_MIN; short maxShort = SHRT_MAX; int minInt = INT_MIN; int maxInt = INT_MAX; long minLong = LONG_MIN; long maxLong = LONG_MAX; unsigned short minUShort = 0; unsigned short maxUShort = USHRT_MAX; unsigned int minUInt = 0; unsigned int maxUInt = UINT_MAX; unsigned long minULong = 0; unsigned long maxULong = ULONG_MAX; // display internal sizes of data types cout << "A short is " << sizeof(short) << " bytes long\n"; cout << "An int is " << sizeof(int) << " bytes long\n"; cout << "A long is " << sizeof(long) << " bytes long\n"; cout << "An unsigned short is " << sizeof(unsigned short) << " bytes long\n"; cout << "An unsigned int is " << sizeof(unsigned int) << " bytes long\n"; cout << "An unsigned long is " << sizeof(unsigned long) << " bytes long\n"; // display ranges of basic integer data types cout << "short: " << minShort << " through " << maxShort << '\n'; cout << "int: " << minInt << " through " << maxInt << '\n'; cout << "long: " << minLong << " through " << maxLong << '\n'; cout << "unsigned short: " << minUShort << " through " << maxUShort << '\n'; cout << "unsigned int: " << minUInt << " through " << maxUInt << '\n'; cout << "unsigned long: " << minULong << " through " << maxULong << '\n'; cont(); return 0; } void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press Enter to continue..."; cin.get(); return; } /* Sample output: A short is 2 bytes long An int is 4 bytes long A long is 4 bytes long An unsigned short is 2 bytes long An unsigned int is 4 bytes long An unsigned long is 4 bytes long short: -32768 through 32767 int: -2147483648 through 2147483647 long: -2147483648 through 2147483647 unsigned short: 0 through 65535 unsigned int: 0 through 4294967295 unsigned long: 0 through 4294967295 Press Enter to continue... */