100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C++

Type Modifiers in C++

Learn what type modifiers are in C++ — signed, unsigned, short, and long — and how they change size and range.

BasicsBeginner6 min readJul 7, 2026
Analogies

1. Intro

Type modifiers are keywords that alter the meaning of a base data type — typically adjusting how much memory it uses and what range of values it can represent. C++ provides four type modifiers: signed, unsigned, short, and long. They can be applied to int, and some (signed, unsigned) can also apply to char, while long can apply to double as well.

🏏

Cricket analogy: Just as a 'captain' tag modifies a player's base role without changing that they're still a batsman, signed, unsigned, short, and long modify a base type like int without changing that it's still fundamentally an integer.

2. Syntax

cpp
modifier data_type variable_name;
// example:
unsigned int count;
long long int totalBytes;

3. Explanation

Each modifier changes how a base type behaves:

🏏

Cricket analogy: Just as each fielding restriction (powerplay, death overs) changes how the same match behaves without changing the sport, each C++ type modifier changes how the same base type behaves in memory and range.

  • signed — can represent both negative and positive values (this is the default for int)
  • unsigned — can only represent non-negative values, but doubles the positive range in exchange
  • short — typically uses less memory than a plain int, for smaller ranges
  • long — typically uses more memory than a plain int, for a larger range (long long extends this further)

For example, on most common modern platforms, a plain int is 4 bytes and can hold roughly -2.1 billion to +2.1 billion. Marking it unsigned keeps the same 4 bytes but shifts the representable range to roughly 0 to +4.2 billion — trading the ability to represent negative numbers for double the positive range. short int typically uses less memory (commonly 2 bytes) for a smaller range, while long long int typically uses more (commonly 8 bytes) for a much larger range.

🏏

Cricket analogy: A plain int is like a regular ODI squad of standard size covering both positive and negative run swings; unsigned keeps the same squad size but drops the 'negative' concept entirely to cover an even bigger positive total, like scoring only, never conceding.

Because exact sizes and ranges are implementation-defined, never hard-code a maximum value — use sizeof() or the constants in <climits> (like INT_MAX) to check the real limits on your platform.

4. Example

cpp
#include <iostream>
using namespace std;

int main() {
    signed int temperature = -15;
    unsigned int population = 4200000000;
    short int smallCount = 100;
    long long int fileSizeInBytes = 9000000000;

    cout << "Temperature: " << temperature << endl;
    cout << "Population: " << population << endl;
    cout << "Small count: " << smallCount << endl;
    cout << "File size: " << fileSizeInBytes << endl;

    return 0;
}

5. Output

text
Temperature: -15
Population: 4200000000
Small count: 100
File size: 9000000000

6. Key Takeaways

  • Type modifiers (signed, unsigned, short, long) adjust the size and/or range of a base type.
  • unsigned removes negative values but extends the positive range.
  • short typically reduces memory usage; long/long long typically increase it for a larger range.
  • Always verify actual sizes/limits with sizeof() or <climits> rather than assuming a fixed value.

Practice what you learned

Was this page helpful?

Topics covered

#CStudyNotes#Programming#TypeModifiersInC#Type#Modifiers#Syntax#Explanation#StudyNotes#SkillVeris#ExamPrep