Data Types in C++






When we write the code, we generally needs to store the data in a entity known as "variables". During the declaration of the variables we need
to be clear that what type of data does it going to store. Here comes in pictures "Data Types". Data types generally give information about the
variable to the compiler and further compiler will allocate or reserve some space in memory for that variable depending on its declared data-type.
In C++ data-types are classified into three types.

  • Built-in or Primitive data-types
  • User defined data-types
  • Derived data-types

Primitive data-types:

These are the data-type which are predefined in the C++ libraray. We can directly use these data types in the code to decleare the variables.
Example of primitive data-types are as below.

Data Type Keyword
Integer int
Floating Point float
Double Floating Point double
Character char
Wide Character wchar
Boolean bool
Valueless or Void void


Syntax for using the data-type in the code is:
< data-type>< variable name> = < value>
Example:
 
Here in this line of code we are declaring a variable of name "a", of data-type integer having value 10.


User defined data-types:

These are the data-types which are defined by the user while coding. For example when we define a class, enum, structure, etc. then we are
creating our own data types. User define data-types are as follow:

Data Type Keyword
Classes class
Structure struct
Enumeration enum
Union union
Typedef typedef

Derived data-types:

These are the data-types which are derived from the primitive or built-in datatypes. Examples of these data-types are:

Data Type
Arrays
Pointers
Reference
Functions