C_Tutorial_Day_3
C_Tutorial_Day_3
Further applying qualifiers to the above data types yield additional data types. A qualifier alters the characte-
ristics of data type such as its size and sign.
short and long qualifiers are used for altering size.
signed and unsigned qualifiers are used for altering sign.
The qualifier short is applicable with only int type whereas long is applicable with int type as well as with
double type.
The qualifiers signed and unsigned are combined with int and char data type.
After applying qualifiers the data type that we can use in C language are:
signed short int
unsigned short int
signed int
unsigned int
short int
int
signed long int
signed long
unsigned long int
unsigned long
long
float
double
long double
signed char
unsigned char
If we have to store some values in variables then this must be informed to computer before storing the value.
This is known as data declaration. If we have to store integer values then we have to judge the type which
can hold the values. e.g. we have to add three numbers as 34567, 567 and -56. To store these values we
create three variables/identifiers let it be a, b and c. The content of a will be 34567 which is positive and
range is above 32767 therefore a can not be of int data type. It can be unsigned int type then we can store
up to 65535 in a. b and c can be of int type because 567 and -56 is within the range of -32768 to 32767. And
we have to think over the output that is the sum of a, b and c which can be of unsigned int (why?) type.
Enumeration Constants
An enumeration is a user defined type with values ranging over a finite set of identifiers called enumeration
constant. Enumeration is a convenient way to associate constant integer with meaningful name. It has the
advantage of generating values automatically. Use of enumeration constants, in general makes the program
easy to read and change at a later date.
For this we have to use keyword enum.
enum grades
{
F, D, C_MINUS, C, C_PLUS, B_MINUS, B, B_PLUS, A_MINUS, A, A_PLUS
}result;
enum grades final_result;
This declaration creates a new type grades and result and final_result as variable of this type, That can only
accept one of the values F,D,….. A_PLUS and no others. These eleven enumerators have the consecutive
integer values 0 (for F) through 10 (for A_PLUS).
The values need not be distinct in the same enumeration. For example
enum weather { hot, warm=0, cold, wet};
Here hot and warm both represent the value 0.