Data Type in C++


 Data Types in C++

    While in the previous tutorial, we discuss the C++ variables with examples. Now we will discuss the Data types in C++.

 

      All data types restrict variables that the data to be stored in it. Whenever a variable is defined in C++, the compiler allocates some memory for that variable based on the data-type with which it is declared.

     There are Three Types of data types.

data type, c++, Variable, coding geeks
  
  1. Primary Data Types 

                These data types are built-in or predefined data types and can be used directly by the user to declare variables. example: int, char , float, boolean etc. Primitive data types available in C++ are:  

  • Integer
  • Floating / Double Floating Points
  • Character
  • Boolean
  • void
  • wide character

    2. Derived  Data Types 

          The data-types that are derived from the primitive or built-in data types are referred to as Derived Data Types. Derived data type are given below:

  • References
  • Pointers
  • Function
  • Arrays

    3. User Defined data types

          These data types are defined by user itself. Like, defining a class in C++ or a structure. Following  are the types of User-defined data-types:

  • Class
  • Structure
  • Enum
  • Unions
  • Typedef

 

    Lets discuss Primary data type in C++.

  •  Integers Keyword use in Integers are int. Basically int  takes 4 bytes memory space range from -2147483648 to 2147483647.
  • Boolean is used for storing boolean or logical values in c++. Typically its stores true and false.
  • Character Character used char  as data type and store character value. Its take 1 byte of memory space range from -128 to 127 or 0 to 255. 
  • void  void means without any value. void datatype represents a valueless entity. Its is used when function does not have data type.
  • Floating points: Keyword used for floating point data type is float. It is used for storing single precision floating point values or decimal values and take 4 byte of memory space.

 

Here is Example of Data type which show size of data types     



No comments