signed Modifier

Signed variables can store positive, negative integers, and zero.

Example:

signed int a = 45;
signed int b = -67;
signed int c = 0;

Here,

  • ‘a’ is a  positive valued integer.
  • ‘b’ is a  negative valued integer.
  • ‘c’ is a zero-valued integer.

Example:

C++




// C++ program to demonstrate
// the signed modifier
#include <iostream>
using namespace std;
 
// Driver Code
int main()
{
    cout << "Size of signed int : " <<
             sizeof(signed int) <<
             " bytes" << endl;
    cout << "Size of signed char : " <<
             sizeof(signed char) <<
             " bytes" << endl;
 
    return 0;
}


Output

Size of signed int : 4 bytes
Size of signed char : 1 bytes

Note: The int datatype is signed by default. So, int can be directly be used instead of signed int.

C++ Type Modifiers

Modifiers are used in C++ to change or give extra meaning to already existing data types. It’s added to primitive data types as a prefix to change their meaning. A modifier is used to change the meaning of a basic type so that it better matches the requirements of different circumstances.

Following are the C++ data type modifiers:

  • signed
  • unsigned
  • short
  • long

These modifiers can be used with the following Built-in Data Types.

Similar Reads

1. signed Modifier

Signed variables can store positive, negative integers, and zero....

2. unsigned Modifier

...

3. short Modifier

Unsigned variables can store only non-negative integer values....

4. long Modifier

...

Important Points about Data Type Modifiers

The short keyword modifies the minimum values that a data type can hold. It is used for small integers that lie in the range of −32,767 to +32,767....

Various Data Types with Modifiers and Their Size in Bytes

...

Type Qualifiers in C++:

The long keyword modifies the maximum values that a data type can hold. It is used for large integers that are in the range of -2147483647 to 2147483647....