Data Types, Variables and Constants

Type Modifiers

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 –

  1. Signed
  2. Unsigned
  3. Short
  4. Long

In Java, there are 2 Type Modifiers –

  1. Signed
  2. 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.

  1. 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;

  1. 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

  1. 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

  1. 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

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?

  1. int
  2. float
  3. double
  4. None of the Above

Answer. Option A.

Q2. signed and unsigned type modifiers are used for?

  1. int, long
  2. char
  3. Both A & B
  4. None of the Above

Answer. Option C.

Q3. Size of unsigned short int in a 32-bit compiler is?

  1. 1 byte
  2. 4 byte
  3. 2 byte
  4. 8 byte

Answer. Option C.

Q4. Range of signed char is?

  1. 0 to 255
  2. 0 to +127
  3. 128 to +127
  4. -128 to +127

Answer. Option D.

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.