The memory in the computer is organized in terms of units called bytes. One byte consists of 8 bits and bit is a smallest unit of memory.
Need of Data Modifiers:
The Need of modifiers can be understood by the help of following.Let us take an example of a Program where we need to input the “Salary” of “Employees” in a team. This program will accept the salary as an input from user and then calculate the Income Tax of that user. We use “int” to store the Salary of the employee as we are assuming that the salary will be in “Whole Numbers”.An integer data type takes 2 Bytes of Memory and we are aware that the Salary of any of the employee can not be “Negative”. We are using “2 Bytes” to store the memory of an Employee and we can easily save 1 Byte over there by removing the “Signed Part” in the integer. This positive value can easily be stored in “1 Bye Int” This leads us to the user of Data Type Modifiers.
Types of Data Modifiers in C:
Basically c programming language consist of 3 basic modifiers.The modifiers are listed below :Signed Type Modifier:
All data types are “signed” by default. Signed Data Modifier implies that the data type variable can store positive values as well as negative values.
For example, if we need to declare a variable to store temperature, it can be negative as well as positive.
signed int temperature;
Or
int temperature;
Unsigned Type Modifier:
If we need to change the data type so that it can only store only store positive values, “unsigned” data modifier is used.
For example, if we need to declare a variable to store the salary of an employee as explained above, we will use “Unsigned” Data Qualifier here.
unsigned int salary;
Long Type Modifier:
Sometimes while coding a program, we need to increase the Storage Capacity of a variable so that it can store values higher than its maximum limit which is there as default. In such situations or programs, we need to make use of the “long” data type qualifier. “long” type modifier doubles the “length” of the data type when used along with it.
For example, if we need to store the “annual turnover” of a company in a variable, we will make us of this type qualifier.
long int turnover;
This variable will take 4 Bytes in memory.
Short Type Modifier:
A “short” type modifier does just the opposite of “long”. If one is not expecting to see high range values in a program and the values are both positive & negative.
For example, if we need to store the “age” of a student in a variable, we will make use of this type qualifier as we are aware that this value is not going to be very high.
short int age;
This variable will consume only 1 Byte in memory.
Example
We can apply the above mentioned modifiers to integer (int) and character (char) base types.1. Integer Type Modifiers:
* We can use all the above mentioned Type Modifiers for int data type in C Language
* Short int and long int are also termed as short and long respectively.
* Int is signed & unsigned by default.
2. Character Type Modifiers:
* Variables of type char consume 1 byte in memory.
* Char can be signed or unsigned only.
* They have a range of -128 to 127 and 0 to 255 for signed & unsigned respectively.
3. Float Type & Double Type Modifier:
There are 3 types of float type modifiers as given below:
* float
* double
* long double
Double is same as long float. Float type occupies 4 bytes of memory. Type double occupies 8 bytes. Long double occupies 10 bytes. The exception to this is long double, which modifies the size of the double data type to 10 bytes. Please note that in some compilers this has no effect.
Note: We may use long modifier with double data type but it cannot be used with float, i.e. long double is allowed but long float is not allowed because long float is equal to double.
Readers are requested to read give the feedback if they like the article(Admin)
ReplyDelete