Data Type C++

Data Type C++
Previous Home Next

Data type can be defined as a type of data that we use in our programs. Each variable that we use in programs must have a data type. In C++, there is 3 types of data types:-

  1. In built data types.
  2. User defined data types.
  3. Derived data types
  1. In built data types:- These are the predefined data types which has special meaning to the compiler.

    eg: int, char, float etc.

    Data Types Size (in bytes) Range
    Char1-128 to 127
    Integer2-32768 to 32767
    Float43.4*10-38 to 3.4*1038
    Double81.7*10-308 to 1.7*10308

    Integer can be further classified into following:

    • Short (-32768 to 32767)
    • Long (-2,147,483,648 to 2,147, 483,647)
    • Unsigned (up to 65536)

    Floating point Data type can be categorized as:

    • Float (3.4E +/- 38 (7 digits))
    • Double (1.7E +/- 308 (15 digits))
    • Long Double (1.7E +/- 308 (15 digits))
  2. Derived data types:- These data types are derived from the in built data types.
  3. .

    eg: Array, Function, Pointer, reference.

    • Array:- Array is derived data type used to store data of similar data type. All elements in array stored in contigous memory location.
    • eg: int mark[100];

      char names[25];

    • Function:- A function is a block of code that performs a specific task. Every function has a function name and it is reusable . it can be executed from as many different parts in Program as required, it can also return a value to calling program. All executable code resides within a function.
    • Pointer:- Pointer is a variable use to store the address of another variable. With the help of pointer we can allocate or de allocate memory to variables.
    • Reference:- Reference is the alternate name or another name to variables. We can use both the names of variable in our program.
  4. User defined data types:-In C++ we can create our own data types known as user defined data types.
  5. eg: Structure, Union, Class, Enumeration.

    • Structure:- In some programming contexts, you need to access multiple data types under asingle name for easy manipulation; for example you want to refer to address with multiple data like house number, street, zip code, country C supports structure which allows you to wrap one or more variables with different data types. A structure can contain any valid data types like int, char, float even arrays and other structures. Each variable in structure is called a structure member.
    • Union:- Union is same as like structure except the allocation of memory for its members.Union occupies lower memory space as comapred to structure.
    • Enumeration:-Enumeration is a set of constant and each constant has a name. We use enum keyword to create enum.
Previous Home Next