Data Types in C++

They are used to define type of variables and contents used. Data types define the way you use storage in the programs you write. Data types can be built in or abstract.

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

  • Fundamental or primitive data types
  • Derived data types
  • User defined data types

Primitive data types

These are the data types whose variable can hold maximum one value at a time, in C++ language it can be achieve by int, float, double, char.

Example

int a;  //  valid
a = 10,20,30;  //  invalid

Derived data types

These data type are derived from fundamental data type. Variables of derived data type allow us to store multiple values of same type in one variable but never allows to store multiple values of different types. These are the data type whose variable can hold more than one value of similar type. In C++ language it can be achieve by array.

Example

int  a[] = {10,20,30};  // valid
int b[] = {100, 'A', "ABC"};   //  invalid

 

User defined data types

User defined data types related variables allows us to store multiple values either of same type or different type or both. This is a data type whose variable can hold more than one value of dissimilar type, in C++ language it is achieved by structure.

Syntax

struct emp
{
int id;
char ename[10];
float sal;
};

 

In C++ language, user defined data types can be developed by using struct, union, enum etc.