Coupon Accepted Successfully!


C++ Data types

  • C++ data types can be classified into three major groups. They are
    • Fundamental data types
    • Derived data types
    • User defined data types
  • Fundamental data types
    • These are data types which are not composed of other data types.
    • They are also used as a basic data type.
    • The following are the data types of this type. They are
  • Integer: It uses the keyword 'int', which stores real numbers. It does not have any fractional part. For example it accepts the values such as 5, 10,-236.
  • Floating point: It uses the key work 'float' which stores fractional values. It is separated with the help of dot (.) operator. Simply called as decimal values. For example it accepts values such as 5.2,10.236,-15.6396
  • Character value: It uses the key work 'char', which stores a single character enclosed in single quotation. For example 'a', 'x', 'A', '1'.




Char or signed char


-128 to 127

Unsigned char


0 to 255

int (or) signed int


-32768 to 32767

unsigned int


0 to 65535

short int (or) signed short int


-128 TO 127

unsigned short int


0 to 255

long int (or) signed long int


-2,147,483,648 to 2,147,483,647

unsigned long int


0 to 4,294,967,295



3.4E-38 to 3.4E+38



1.7E-308 to 1.7E+308

long double


3.4E-4932 to 1.1E+4932

  • Double precision data type: It uses the keyword 'double' which stores floating point values. It occupies twice the space of float data type.
  • The following table shows the data types along with the modifiers​
Note: Fundamental data type is also called as basic data type.

Derived Data types

  • These are data types which arise with the combination of the base data type.
  • They are
    • Arrays: The application of arrays in C++ is similar to that in C. Array refers to data of similar type stored in a single variable. These data share a common name with different index values. The index value starts from 0 to n-1. The array can be classified as
      • One dimensional array
        • An array name with only one subscript is known as one dimensional array. The general form and example

Array_name [subscript]


  • Two dimensional array
    • An array with two subscripts is known as two dimensional arrays. The general form and example



  • Functions: Functions have undergone major changes in C++. While some of these changes are simple, other requires a new way of thinking when organizing our programs. Many of these modifications and improvements were driven by the requirements of the object oriented concept of C++. The function declaration gives the instruction to the compiler that the function body comes later. The general format and example

<return type> function name(<argument list>)

int add(int a, int b)



return( )

  • Pointers: A pointer variable holds the address of a memory. The address is usually the location of a variable. It uses a symbol called asterisk '*' to refer the pointer data. The pointer is declared as follows

    int *ip;



Note: '&' refers to address of the memory location. The symbol '*' holds the value of a variable.
  • User defined data types
    • These data types are defined by the user. They are
      • Enumeration: This allows us to define our own data type with predefined values. The general form is

Enum userdefinedname





value n


Where enum - keyword
Userdefinedname - valid C++ name
value1, value2, value3....value n are list of constant.


enum a{value1=15,value2=20..... value n=50};

  • Structure: A structure is defined as a data type to represent different types of data with a single name. The data items in a structure are called the members of the structure. The general format is

struct tag-field
datatype member1;

datatype member2;



datatype membern;

Where struct - keyword to define structure
Tag-field- name of the structure
Datatype- valid datatype such as int, float etc.

Struct student

{ int number;

int age;

char sex;



Rules to be followed to implement structure
  1. Tag-field is the name given to the structure
  2. Each member definition should be terminated with a semicolon.
  3. Since structure definition has compound statements, it should have its own opening and closing braces.
  4. The semicolon after the closing brace is a must.
    • Class: A class represents a group of similar objects. It is used as a user defined data type. The class bears the same relationship to an object that a type does to a variable. The general format

class class-name

datatype member1;

datatype member2;



datatype member n;


Where class is a keyword
​Class-name user defined variable
datatype member1, datatype member2 are the data types and its values.


class student

int roll_no;

int age;

char name;


Hierarchy of C++ data types

Test Your Skills Now!
Take a Quiz now
Reviewer Name