Data Types in C++

Data Types are used to define the operations and store each of them. Data types in C++ can be classified into three major categories :
1. User-defined data type
2. Built-in data type
3. Derived data type

User-defined data type:

In C++, User-defined data types are Structure, Union, Class and enum etc.

  • Structure : Structures are used for grouping together elements with dissimilar types. It is often required to group logically related data items together. It has the following syntax :
    struct name
      data type member1;
      data type member2;

  • Union : Unions are conceptually similar to structures, it allows us to group together dissimilar type elements inside a single unit. In unions, the same memory space is used for representing different member elements. As a result, union members can only be manipulated exclusively of each other. It has the following syntax :
    union name
      data type member1;
      data type member2;

  • Class : In C++, Class is a user-defined data type which is used to declare variables.

  • Enum : An enumerated data type is also a user-defined data type which provides a way for attaching names to numbers, it increasing comprehensibility of the code. The enum keyword is used to assign those enumerate values.
    Example :
    enum shape{square, cirle};
    enum color{blue, green};

    Built-in data type:

    In C++, Built-in data types are given as follows:

    char1-128 to 127
    unsigned10 to 255
    int2-32768 to 32767
    unsigned int20 to 65535
    long int4-2147483648 to 2147483647
    unsigned long int40 to 4294967295
    float43.4E-38 to 3.4E+38
    double81.7E-308 to 1.7E+308
    long double103.4E-4932 to 1.1E+4932