Search⌘ K

Data Type Modifiers

Explore how data type modifiers in C++ alter the storage size and value range of primitives like int, double, and char. Understand the use of long, short, unsigned, and signed modifiers to handle different numeric limits and optimize memory in your programs.

Introduction #

The maximum value that can be stored in a variable of type int is 2147483647. What if we want to store a value greater than 2147483647?

Run the code below and see the output!

C++
#include <iostream>
using namespace std;
int main() {
// Initialize variable
int number = 2147483649;
// Display variable value
cout << number;
}

If we run the code given above, it does not give us the expected output. The above code should print 2147483649, but it is printing -2147483647 in output. So how can we handle values greater than the range of a data type? Similarly, how can we decrease the amount of space allocated to a particular variable? Here, data type modifiers come to the rescue.


...