CPP Tutorial

CPP examples programs

CPP Data Types

CPP Data Types are used to define the type of data that is to be stored. CPP data types can be classified into 4 groups:

Basic Data Types:

  1. Integer
  2. Float
  3. Double
  4. Character

Derived Data Types:

  1. Array
  2. Pointer

Enumeration Data Types:

  1. Enum

User Defined Data Types:

  1. Structure

 

Basic Data Types:

Integer: All the non-decimal numbers are called as Integers. Various forms of integers are listed below.

Data Types SIZE (Byte)

For 32 bit

RANGE
short 2 −32,768 to 32,767
signed short 2 −32,768 to 32,767
unsigned short 2 0 to 65,535
int 2 −32,768 to 32,767
signed int 2 −32,768 to 32,767
unsigned int 2 0 to 65,535
short int 2 −32,768 to 32,767
signed short int 2 −32,768 to 32,767
unsigned short int 2 0 to 65,535
long int 4 -2,147,483,648 to 2,147,483,647
signed long  int 4 -2,147,483,648 to 2,147,483,647
unsigned long int 4 0 to 4,294,967,295

Float:

Float represents all the decimal and exponential numbers. The float size is of 4 bytes.

Double:

Double also represents all the decimal and exponential numbers. Various forms of double are listed below.

Data Types SIZE (Byte) For 32 bit
double 8
long double 10

Character:

Various forms of characters are listed below.

Data Types SIZE (Byte) RANGE
char 1 −128 to 127
signed char 1 −128 to 127
unsigned char 1 0 to 255

 

Example:

#include <iostream.h>
using namespace std; 
int main()
{
int num1;
float num2;
char ch;
cout << "Enter an integer: ";
cin >> num1;
cout << "Enter a decimal number: ";
cin >> num2;
cout << "Enter a letter: ";
cin >> ch;
cout << “You Entered an Integer:<< num1 << endl; 
cout << “You Entered a Decimal Value:<< num2 << endl; 
cout << “You Entered a Character:<< ch << endl; 
return 0;
}

Output:

Enter an integer: 5
Enter a decimal number: 4.5
Enter a letter: A
You Entered an Integer: 5
You Entered a Decimal Value: 4.5
You Entered a Character: A