Data Types in C++

C++ Data Types:

Data Types are used to define the operations and store each of them. It 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, enum etc.

  • Structure: Structures are used for grouping elements with dissimilar types. It is often required to group logically related data items. 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 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 by 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, increasing the 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:

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