C++ Type Modifiers

Last Updated : 13 Jun, 2026

Type modifiers are keywords that alter the properties of fundamental data types in C++. They are used to modify the size, range, or sign of a data type without creating a completely new type.

  • Type modifiers allow programmers to control how values are represented and stored in memory.
  • C++ provides four type modifiers: signed, unsigned, short, and long.

For example, an unsigned int can store a larger range of positive values than a regular int, while a short int typically requires less storage than an int.

Type Modifiers in C++

C++ provides the following type modifiers:

Modifiers in C++

1. signed Modifier

The signed modifier indicates that a variable can store both positive and negative values.

Syntax

signed type name;

The signed modifier is primarily used with integer and character types.

C++
#include <iostream>
using namespace std;

int main() {

    cout << "Size of signed int: "
         << sizeof(signed int)
         << " bytes" << endl;

    cout << "Size of int: "
         << sizeof(int)
         << " bytes";

    return 0;
}

Output
Size of signed int: 4 bytes
Size of int: 4 bytes

Explanation: For integer types, int is signed by default. Therefore, the following declarations are equivalent

int num;

signed int num;

2. unsigned Modifier

The unsigned modifier indicates that a variable can store only non-negative values. Since no bits are reserved for storing a sign, the positive range becomes larger than the corresponding signed type.

Syntax

unsigned type name;

C++
#include <iostream>
using namespace std;

int main() {

    unsigned int x = -10;

    cout << x;

    return 0;
}

Output
4294967286

Explanation: Unsigned types cannot represent negative values. When a negative value is assigned to an unsigned integer, it is converted according to the rules of unsigned arithmetic, producing a large positive value.

In practice, assigning negative values to unsigned variables should generally be avoided unless the conversion is intentional.

3. short Modifier

The short modifier is used with integer types to provide a smaller range than a regular int.

Syntax

short type name;

C++
#include <iostream>
using namespace std;

int main() {

    cout << "Size of short int: "
         << sizeof(short int)
         << " bytes" << endl;

    cout << "Size of int: "
         << sizeof(int)
         << " bytes";

    return 0;
}

Output
Size of short int: 2 bytes
Size of int: 4 bytes

Explanation: On many modern systems, short int occupies 2 bytes while int occupies 4 bytes. However, the exact size is implementation-dependent.

The C++ standard guarantees:

sizeof(short) <= sizeof(int)

4. long Modifier

The long modifier is used to increase the range of a data type.

Syntax

long type name;

The long modifier can be used with int and double

It can also be repeated with integers:

long long int

C++
#include <iostream>
using namespace std;

int main() {

    cout << "Size of int: "
         << sizeof(int)
         << " bytes" << endl;

    cout << "Size of long int: "
         << sizeof(long int)
         << " bytes" << endl;

    cout << "Size of double: "
         << sizeof(double)
         << " bytes" << endl;

    cout << "Size of long double: "
         << sizeof(long double)
         << " bytes";

    return 0;
}

Output
Size of int: 4 bytes
Size of long int: 8 bytes
Size of double: 8 bytes
Size of long double: 16 bytes

Explanation: On many 64-bit systems:

  • long int typically occupies 8 bytes.
  • long double usually provides greater precision than double.

However, the exact size may vary depending on the compiler and platform.

Size and Range of Modified Data Types

The exact size and range of modified types depend on the compiler and platform. The following table shows common values on modern 64-bit GCC systems.

Data TypeModifiersSize (bytes)Range
charsigned1-128 to 127
unsigned (default)10 to 255
short intsigned (default)2-32,768 to 32,767
unsigned20 to 65,535
intsigned (default)4-2,147,483,648 to 2,147,483,647
unsigned40 to 4,294,967,295
long intsigned (default)8-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned80 to 18,446,744,073,709,551,615
long long intsigned (default)8-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned80 to 18,446,744,073,709,551,615
doubleNone8~1.7E-308 to 1.7E+308
long doubleNone16Higher precision, range varies depending on implementation

These values are implementation-dependent and should not be assumed for every compiler or operating system.

When to Use Type Modifiers

Type modifiers are useful when:

  • You need a larger range of positive values (unsigned).
  • You want to optimize memory usage for integer data (short).
  • You need to store very large integer values (long or long long).
  • You require greater floating-point precision (long double).
Comment