Data Types in C++ | Primary Data Types of C++ 

Primary Data Types of C++ 
You must first complete Constant in C++ | Literals in C++  before viewing this Lesson

Data Types in C++ | Primary Data Types of C++ 



What is a Data type in C++?

Data type  specifies the type and range of values that can be stored in a variable. Different types of data types in C++ are

Primary Data Types in C++

Primary data types are provided by C++ and  can use them as such without making any modifications to them.

There are four primary data types in C++ 

i. Integer Data Type in C++

Integer data type can contain numbers without decimal point. They can take both positive and negative values.

Different categories of integer data type are explained in following table.

Name of Data Type Size Range of Values
short 2 bytes -215 to 215 –1

(-32768 to 32767)

signed short 2 bytes -215 to 215 –1

(-32768 to 32767)

unsigned short 2 bytes 0 to 216-1

(0 to 65535)

int 4 bytes (-2,147,483,648 to 2,147,483,647)
signed int 4 bytes (-2,147,483,648 to 2,147,483,647)
unsigned int 4 bytes (0 to 4,294,967,295)
long 4 bytes -231 to 231 –1

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

signed long 4 bytes -231 to 231 –1

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

unsigned long 4 bytes 0 to 231 –1

(0 to 4,294,967,295)

ii. Floating point Data Type in C++

This data type to store numeric values with decimal point. They can also take positive and negative values. As we discussed in Constants, they can store values both in standard form and as exponent form.

Different categories of floating point data type are explained in following table.

Name of Data Type Size Range of Values
float 4 bytes ±3.4X10-38 to ±3.4X 10+38
double 8 bytes ±1.7X10-308 to ±1.7X 10+308
long double 12 bytes ±3.4X10-4932 to ±3.4X 10+4932

 

iii. Character Data Type in C++

This data type can store alphabets, digits, special characters and spaces.

Different categories of character data type are explained in following table.

Name of Data Type Size in Bytes Range of Values
char 1 -27 to 27 –1

(-128 to 127)

signed char 1 -27 to 27 –1

(-128 to 127)

unsigned char 1 0 to 28 –1

(0 to 255)

 

iv. void Data Type in C++

void basically means empty so this data type is specifies that a function doesn’t return anything.



Spread the love
Lesson tags: Character Data Type in C++, Floating point Data Type in C++, Integer Data Type in C++, Primary Data Types in C++, What is a Data type in C++
Back to: C++ Programming Notes
Spread the love