To limit the data that can be stored, all variables declare Data Types in C++. Data can be of many types such as character, integer, real, etc.
C++ Programming Language like any other language provides many ways and facilities to handle different types of data by providing data types.
Data types in C++ are declarations of variables. This defines the type and size of data that is associated with variables. This could be, for example:
int ball = 42;
Here, the ball is a variable of type int, and int has 2 or 4 bytes of storage memory. This means the variable can store the integer in either 2 or 4 bytes.
C++ Data Types
Data types are means to identify the type of data and associated operations for handling it, which means how much memory we are allocating to a variable depends on data types. There are three types of data types:
- Primitive Data Type
- Derived Data Type
- User-defined Data Type

1. Primitive Data Types-
They are predefined or built-in data types and for declaring variables they can be directly used. Primitive data types in c++ are:
- Integer
- Character
- Boolean
- Float
- Double
- Void
1. Integer Type
- An integer is a keyword used to describe integer data types.
- Integers usually require 4 bytes of memory space.
- It can range from -21474836484848 to 2147483647.
- For Example:
int age = 85;
2. Character
- Character is used to store characters.
- char is the keyword used to define the character data type.
- Characters usually require 1 byte of memory space.
- It can range from -128 through 127, 0 to 255, and 0 to 255.
- For Example:
char name = 'r';
3. Boolean
- This data type uses boolean and logical values to store.
- A boolean variable stores true or false.
- bool is the keyword used to describe boolean data types.
- For Example:
bool ans = false;
4. Floating-Point
- The data type for floating-point values is used to store single-precision floating points values.
- float is the keyword for floating-point data types.
- Float variables usually require 4 bytes of memory space.
- For Example
float size = 64.74;
5. Double
- The double data type can be used to store double-precision floating-point values or decimal numbers.
- double is the keyword for the double floating points data type.
- Double variables usually require 8 bytes of memory space.
- For Example
double height = 45E12
6. Void
- Void is a text that has no value.
- A void data type is an entity without value.
- A function that does not return a value is called void data type.
2. Derived Data Type
These data types come from built-in or primitive data types are called Derived Data Types. They can be one of the following types:
- Function
- Array
- Pointer
- Reference
3. User-defined Data Type
These data types can be defined by the user. For example, you can define a class or structure in C++. C++ offers the following data types that can be customized by users:
- Class
- Structure
- Union
- Enumeration or Enum
We will learn in brief about derived data types and user-defined data types in later tutorials.
Type Modifier in C++
You can modify certain fundamental data types further by using type modifiers. C++ has four types of modifiers. These are:
signed
unsigned
short
long
You can modify the data types below using the modifiers.
int
double
char
DATA TYPE | SIZE IN BYTES | DESCRIPTION |
Signed Int | 4 | used for integers (equivalent to int ) |
Unsigned Int | 4 | Store only positive integers |
short | 2 | Integer range -32768 to 32767 |
unsigned short | 2 | Small Positive integer range 0 to 65,535 |
long | at least 4 | Used for large integer |
unsigned long | 4 | large positive integers or 0 |
long long | 8 | very large integers like long long int |
unsigned long long | 8 | very large positive integers or 0 |
long double | 12 | used for large floating-point numbers |
signed char | 1 | characters guaranteed range -127 to 127 |
unsigned char | 1 | characters range 0 to 255 |
Type modifiers can be used in C++ programming to modify the meaning of fundamental data types.
Type modifiers can be used in C++ programming to modify the meaning of fundamental data types.
There are lots of topics yet to cover and we will do it in further blogs. Some topics are:
- Introduction to C++ Programming Language
- Installation of C++
- Data Types in C++
- Variables in C++ Programming Language
- C++ Operators and Expressions
and many more topics are yet to come, so be updated to our website (BeAware World)
Read More: What Is Big Data? – Characteristics Of Big Data
[…] Data Types in C++ […]
[…] Data Types in C++ […]
[…] Data Types in C++ […]