27. TYPEDEF KEYWORD –
typedef is one of the C keywords which allows user to define a new name for an existing data type. Furthermore, we can defined new data type names by using the keyword typedef.
We do not create a new data type, but rather we define a new name for an existing type. This process can help make machine-dependent programs more Portable.
The typedef keyword also can aid in self-documenting your code by allowing descriptive names for standard data types.
keyword_name data_type new_name;
Here, typedef is the keyword_name. data_type is any existing data type that may be a standard data type or a user defined type. new_name is an identifier, which is the new name for this data type.
typedef int marks;
Here, marks is a synonym for int and we can use marks instead of int anywhere in the program. Such as,
marks sub1, sub2;
Here, sub1, sub2 are actually int variables and are similar to any variable declared using int keyword.
28. UNION KEYWORD –
union is one of the C keywords which provides a way of interpreting the same bit pattern in two or more different ways. Likewise structure, we use the union keyword to declare a union.
A union is a memory allocation that is shared by two or more different types of variables. Likewise structure, union is also a derived data type and it also contain members of different data types.
The main difference between union and structure is in the way the compiler allocates memory for the members. In a structure each member has its own memory allocation, whereas members of union share the same memory allocation.
……. …… ……. ……
……. …… ……. ……
Likewise structure, union also contains different types of variables having different data types. Also, the syntax of union is same as structure.
29. UNSIGNED KEYWORD –
Likewise signed, unsigned is one of the C keywords which we use in type qualifiers with different data types. Generally, unsigned is a type qualifier which when we use with data types, represents the number as always positive.
The size and range of different Data types with unsigned qualifier is given below,
- First of all, the size of unsigned char is 1 byte and it ranges from 0 to 255.
- On the other side, the size of unsigned integer is 2 bytes and it ranges from 0 to 65535.
- Talking about unsigned short int, it takes 1 byte from the memory and ranges from -128 to 127.
- Also, the size of unsigned long int is 4 bytes and it ranges from 0 to 4294967295.
Keyword_name data_type variable_name;
Here, keyword_name is unsigned. The data_type is usually integer data type i.e. int or Character data type i.e. char. And the Variable_name depends upon user’s choice.
unsigned int num;
unsigned char grade;