Loading...
C++

Data Types of C++

Data type is a keyword used to  identify type of  data. It is used to storing the input of the program into the main memory (RAM) of the computer by allocating sufficient amount of memory space in the main memory  of the computer.

In general every programming language is containing three categories of data types. They are

  • Fundamental or Primitive Data Type
  • Derived Data Type
  • User Defined Data Type
  1. Primitive or Build-in Data Type:
    These are the data type which are predefined and wired directly into the compiler. Example: int, char, float etc
    Type Name                Bytes      Range of Values
    int                                 4            2,147,483,648 to 2,147,483,647
    unsigned int                 4            0 to 4,294,967,295
    bool                             1             false or true
    char                             1             128 to 127
    signed char                  1             128 to 127
    unsigned char              1             0 to 255
    short                             2             32,768 to 32,767
    unsigned short              2             0 to 65,535
    long                               4             2,147,483,648 to 2,147,483,647
    unsigned long               4             0 to 4,294,967,295
    long long                       8             9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 
    unsigned long long        8             0 to 18,446,744,073,709,551,615
    float                               4              3.4E +/- 38 (7 digits)
    double                           8              1.7E +/- 308 (15 digits)
    long double                same as      Same as double
                                       double
    wchar_t                          2              0 to 65,535
  2. Derived Data Types:
    These are derived from the fundamental data types. Derived data type variables allows us to store multiple values of same type in one variable but never allows storing multiple values of different types. These are the data type whose variables can hold more than one value of similar type. 
  3. User Defined Data Types:

    typedef Declarations:

    We can define our own name for a build in data type. For this we have to use typedef keyword. The declaration of a new name for a built in type is given below
    Syntax:  typedef BuiltInDataType NewName;
    Example:  typedef int FirstInt;

    enum Keyword:
    The other way of creating our own data is by using enumeration. An enumeration is a set of possible values. It is declared by using the keyword “enum”.
    Syntax:  enum EnumName{list of possible values};
    Example:  enum cities{Telangana, AndhraPradesh, Kerela}; 

Leave a Reply

Your email address will not be published. Required fields are marked *