We all know that there are various different Data types that are supported by the programming languages in order to store different values in the memory location. Type Modifiers are used to modify or add special meaning to the predefined data types. Let us learn more about these Type Modifiers in the article below.
Definition
Type Modifiers are special keywords defined in the programming language which are used to modify the default properties of the Built-in Data types.
Type Modifiers are special keywords that are used to modify the range of the data types and also the memory space allocated to the variable.
Type Modifiers
Type Modifier keywords are used as prefixes to the Built-in Data types in the declaration or initialization statements. They are used to modify the memory allocation of the variable. Type Modifiers also modify (increase or decrease) the range of the Data types.
Different Type Modifiers
Depending on the programming language, there are a different number of Type Modifiers.
In C and C++, there are 4 Type Modifiers namely –
- Signed
- Unsigned
- Short
- Long
In Java, there are 2 Type Modifiers –
- Signed
- Unsigned
Type modifiers signed, unsigned, long, and short are prefixed and used with integer base data types. Whereas signed and unsigned are used for char, long can also be used for double base data types.
short and long Type Modifiers can also be used as a prefix for signed and unsigned type modifiers too and vice versa.
Let’s look at each one of them in detail.
-
Short Type Modifier –
This type modifier is used to save memory space. They are used to modify the maximum and minimum value the data type will hold. We use short for small integers. There does not exist any short floating type. Short Type Modifier is only used on the int data type.
Example –
short int a = 21324;
-
Long Type Modifier –
It is used to increase the current size of the data type. This type modifier is used to store large numbers. The type long float is not a legal type. Type Modifier is used on int and double data type.
Example –
long int x = 1234567 ;
long double c =Â 10.2345 ;
Size Hierarchy –
short int < int < long int
-
Signed Type Modifier –
This special keyword is used for holding both positive as well as negative numbers. This type modifier is the default modifier for every data type.
Example
int a = 30 ;
int b = -30 ;
signed int z = 45 ;
signed int x = -100 ;
signed char c = ‘A’ ;     // It consumes 8 bits of memory with sign bit in its memory
-
Unsigned Type Modifier –
This type modifier is used to hold only non-negative i.e. only positive values in the variable.
Example –
unsigned int a = 35 ;Â Â Â Â Â Â Â Â Â // right declaration
unsigned int x = -25 ;Â Â Â Â Â Â Â Â // wrong declaration
unsigned char ch = ‘Z’ ;          // It consumes all 8 bits of memory without any sign bit
Browse more Topics Under Data Types, Variables and Constants
- Concept of Data types
- Built-in Data Types
- Constants in Programing LanguageÂ
- Access Modifier
- Variables of Built-in-Datatypes
- Declaration/Initialization of Variables
- Assignment Statement
Type Modifiers and their Ranges
Type | Bytes | Range |
signed char | 1 | -128 to +127 |
unsigned char | 1 | 0 to 255 |
int | 2 | -32,768 to +32,767 |
signed int | 2 | Same as int |
unsigned int | 2 | 0 to 65,535 |
signed short int | 2 | Same as int |
unsigned short int | 2 | 0 to 65,535 |
long | 4 | -2,147,438,648 to +2,147,438,647 |
signed long | 4 | Same as long |
unsigned long | 4 | 0 to 4,294,967,295 |
float | 4 | -3.4e38 to +3.4e38 |
double | 8 | -1.7e308 to +1.7e308 |
long double | 10 | -1.7e4932 to +1.7e4932 |
Note: Sizes and Ranges vary according to the Compiler. The sizes in the above figure are for a 32-bit compiler.
FAQs on Type Modifiers
Q1. short type modifiers can be used on?
- int
- float
- double
- None of the Above
Answer. Option A.
Q2. signed and unsigned type modifiers are used for?
- int, long
- char
- Both A & B
- None of the Above
Answer. Option C.
Q3. Size of unsigned short int in a 32-bit compiler is?
- 1 byte
- 4 byte
- 2 byte
- 8 byte
Answer. Option C.
Q4. Range of signed char is?
- 0 to 255
- 0 to +127
- 128 to +127
- -128 to +127
Answer. Option D.
Leave a Reply