Data Type in C++

There are four types of data type in C language.  They are as follows:

TypesData Types
Basic data typesint, char, float, double, boolean
User Defined data type structure, union, enum
Derived data type Pointer, array, function

Basic Data Types In C Language

Integer Data Type

Integer data ( example 1,2,3,4,5,6, ….. etc. ) is stored in int ,short and long data type.

Type Storage size Value range
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295

Example: Addition of integer numbers

OUTPUT

Character Data Type

Character data ( example ‘a’ , ‘b’ , ‘f’, ….. etc. ) is stored in “char” data type.

Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127

Example: Declare and initialize integer variable.

OUTPUT

Float Data Type

Floating point value (example  11.23, 333.3330 etc. ) can be stored in data type float and double. Small floating value can be stored in float and large floating stored in double. 

Type Storage size Value range Precision
float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
double 8 byte 2.3E-308 to 1.7E+308 15 decimal places

Example: Declare and initialize float & double variable.

OUTPUT

Categories C++