Data Types in Cpp

 

Data Types in C++




The variable type specifies the type of data that can be stored in it. Each variable is declared by its type.

C++ has five basic data types. These data types are:

  • int               Integer
  • float            Floating Point
  • double         Double Precision
  • char             Characters
  • bool             Boolean

The first four data types are also available in C language. The bool is data type a new addition in C++.




The int Data Type

The int represent the integer data. It is used to declare integer type variables.
An integer is a whole number, i.e. a number without a fraction or a decimal point. For example, 601, 249, -1 and 494 are integers.

The range of values that can be stored in int data type variables depends upon the computer system being used. In MS DOS, an integer type variable takes two bytes in memory and the range of values stored in from -32768 to 32767.


Example:

int age = 13;


The float Data Type

The float represent real or floating type data.

The real type data is represented in decimal or exponential notation. Float type data may be singed or unsigned. For example, 23.3, 12.5, 0.332, -9.32 are example of floating type data.

The storage capacity for float type variable is four bytes and it can store real values from 3.4*10^38.

Example:

float area = 64.74;


The long float Data Type

The storage capacity of a long float type variable is twice the storage capacity of float type variable. Its storage capacity is 8  bytes.


The double Data type

The double is real or floating type data. Its storage capacity is twice the capacity of float data type. It is used to store large real values.

The storage capacity for a double type variable is 8 bytes and it can store real values from 1.7*10^-308 to 1.7*10^308.

Example:

double distance = 45E12    // 45E12 is equal to 45*10^12


The char Data Type

The char stands for character. It is used to declare character type variable.
In character type variables, alphabetic characters, numeric digits and special characters can be stored.

The storage capacity for a single character is 8 bit or one byte. A char type variable can hold from 1 byte to 65536 bytes.

Arithmetic operations can also be performed on char type variables.


Example:

char test = 'z';


The bool Data Type

The word bool stands for boolean. It is used to declare logical type varaibles.
In a logical type variable, only two values true or false can be stored. The true is equivalent to 1 and false to 0.

Example:

bool c = false;




Post a Comment

Previous Post Next Post