Limit Test


LimitTest.cpp

Program listing

/************************************************************************
*                                                                       *
*   Program:    Limit Test                                              *
*                                                                       *
*   Purpose:    This program will display the built-in limits on the    *
*               fundamental types                                       *
*                                                                       *
************************************************************************/

#include <iostream>
#include <string>
#include <limits.h>
#include <float.h>

using namespace std;

int main() {

//  Unsigned and signed characters

    cout << "unsigned char" << endl;
    cout << "\tUCHAR_MAX = " << UCHAR_MAX << endl << endl;
    cout << "char" << endl;
    cout << "\tCHAR_MIN = " << CHAR_MIN << endl;
    cout << "\tCHAR_MAX = " << CHAR_MAX << endl << endl;

//  Unsigned and signed shorts

    cout << "unsigned short" << endl;
    cout << "\tUSHRT_MAX = " << USHRT_MAX << endl << endl;
    cout << "short" << endl;
    cout << "\tSHRT_MIN = " << SHRT_MIN << endl;
    cout << "\tSHRT_MAX = " << SHRT_MAX << endl << endl;

//  Unsigned and signed ints

    cout << "unsigned int" << endl;
    cout << "\tUINT_MAX = " << UINT_MAX << endl << endl;
    cout << "int" << endl;
    cout << "\tINT_MAX = " << INT_MAX << endl;
    cout << "\tINT_MIN = " << INT_MIN << endl << endl;

//  Unsigned and signed longs

    cout << "unsigned long" << endl;
    cout << "\tULONG_MAX = " << ULONG_MAX << endl << endl;
    cout << "long" << endl;
    cout << "\tLONG_MIN = " << LONG_MIN << endl;
    cout << "\tLONG_MAX = " << LONG_MAX << endl << endl;

//  Unsigned and signed long longs

    cout << "unsigned long long" << endl;
    cout << "\tULLONG_MAX = " << ULLONG_MAX << endl << endl;
    cout << "long long" << endl;
    cout << "\tLLONG_MIN = " << LLONG_MIN << endl;
    cout << "\tLLONG_MAX = " << LLONG_MAX << endl << endl;
    cout << "float" << endl;

//  floats, doubles, and long doubles

    cout << "\tFLT_MIN = " << FLT_MIN << endl;
    cout << "\tFLT_MAX = " << FLT_MAX << endl << endl;
    cout << "double" << endl;
    cout << "\tDBL_MIN = " << DBL_MIN << endl;
    cout << "\tDBL_MAX = " << DBL_MAX << endl << endl;
    cout << "long double" << endl;
    cout << "\tLDBL_MIN = " << LDBL_MIN << endl;
    cout << "\tLDBL_MAX = " << LDBL_MAX << endl << endl;
    
    return 0;
}

Sample run

unsigned char
    UCHAR_MAX = 255

char
    CHAR_MIN = -128
    CHAR_MAX = 127

unsigned short
    USHRT_MAX = 65535

short
    SHRT_MIN = -32768
    SHRT_MAX = 32767

unsigned int
    UINT_MAX = 4294967295

int
    INT_MAX = 2147483647
    INT_MIN = -2147483648

unsigned long
    ULONG_MAX = 4294967295

long
    LONG_MIN = -2147483648
    LONG_MAX = 2147483647

unsigned long long
    ULLONG_MAX = 18446744073709551615

long long
    LLONG_MIN = -9223372036854775808
    LLONG_MAX = 9223372036854775807

float
    FLT_MIN = 1.17549e-38
    FLT_MAX = 3.40282e+38

double
    DBL_MIN = 2.22507e-308
    DBL_MAX = 1.79769e+308

long double
    LDBL_MIN = 2.22507e-308
    LDBL_MAX = 1.79769e+308


Previous example
Next example

e-mail me at robbk@hsc.edu

This page was last modified on Thu Sep 9 14:41:52 1999 .

URL: http://people.hsc.edu/faculty-staff/robbk/Coms261/Examples/LimitTest.html

Return to Coms 261 home page