Skip to main content
Engineering LibreTexts

5.1: Integer Data Type

  • Page ID
    10261
  • General Discussion

    The integer data type has two meanings:

    • The integer data type with its various modifiers that create different domains
    • The integer family which also includes the Boolean and character data types

    The integer data type basically represents whole numbers (no fractional parts). The integer values jump from one value to another. There is nothing between 6 and 7. It could be asked why not make all your numbers floating point which allow for fractional parts. The reason is twofold. First, some things in the real world are not fractional. A dog, even with only 3 legs, is still one (1) dog not ¾ of a dog. Second, integer data type is often used to control program flow by counting, thus the need for a data type that jumps from one value to another.

    The integer data type has the same attributes and acts or behaves similarly in all programming languages. The most often used integer data type in C++ is the simple integer.

    C++ Reserved Word int
    Represent Whole numbers (no fractional parts)
    Size Usually 4 bytes
    Normal Signage Signed (negative and positive values)
    Domain (Values Allowed) -2,147,483,648 to 2,147,483,648
    C++ syntax rule Do not start with a 0 (zero)
    C++ syntax rule No decimal point

    Within C++ there are various reserved words that can be used to modify the size or signage of an integer. They include: long, short, signed and unsigned. Signed is rarely used because integers are signed by default – you must specify unsigned if you want integers that are only positive. Possible combinations are:

    C++ Reserved Word Combination Signage
    short int signed
    unsigned short int unsigned
    int signed
    unsigned int unsigned
    long int signed
    unsigned long int unsigned

    The domain of each of the above data type options varies with the complier being used and the computer. The domains vary because the byte size allocated to the data varies with the compiler and computer. This effect is known as being machine dependent. Additionally, there have been some size changes with upgrades to the language. In "C" the int data type was allocated 2 bytes of memory storage on an Intel compatible central processing unit (cpu) machine. In "C++" an int is allocated 4 bytes.

    These variations of the integer data type are an annoyance in C++ for a beginning programmer. For a beginning programmer it is more important to understand the general attributes of the integer data type that apply to most programming languages.

    Definitions

    Machine Dependent
    An attribute of a programming language that changes depending on the computer's CPU.