Compiler is a software designed to execute any program. But it needs be told before – hand what type of data will be fed. Here comes the concept of Data Types.
So data types of data that is to be used in the program. In C there are two categories of data types:-
1. Pre – defined data types
2. User – defined data types
But the user – defined data types are those which are not defined previously. The user defines it according to the need with the help of some predefined reserved keywords. So these are more flexible and very useful.
Pre – defined data-types are such as int, float, char, double, void.
The user – defined data – types can be defined using the following reserved keywords. Those keywords are typedef, enum, structure, union.
Pre – defined data types:-
<data type> <variable name>;
<variable name> = <value>;
where <data types> are those which are defined below.
<variable name> are the name assigned by you to store that type of value.
<value> are the data which you want to store.
- Integer:- This type of data is generally referred to the numeric values or whole numbers. The keyword used to define this type of variable to store data is “int”.
- Float:- This type of data is generally referred to the fractional or decimal number values. The keyword used to define this type of variable to store data is “float”.
- Character:- This type of data is generally referred to the alphabetic values. These types of variables can store one alphabet at a time. The keyword used to define this type of variable to store data is “char”.
- Double:- This type of data is generally is also used to refer the fractional or decimal values but with the larger precision or more after decimal places. The keyword used to define this type of variable to store data is “double”.
User – defined data types:-
- Typedef:– This is used to change the name of a pre – existing data – type. The keyword used is “typedef”.
typedef <type> <new_type>;
where “typedef” is the reserve word.
“<type>” is the existing data-type.
“<new_type>” is the new type.
typedef float abc;
abc x; // this declaration is same as “float abc;”
- Enumeration:- This is used to create a new data-type. The content of the datatype can be given at declaration time. The keyword “enum” is used.
- Structure:- This is used to group a certain number of data-types. It is used to store values. When there are many number of data – types stored in structure the memory it occupies is the sum of all the data-types used. For example, if we use int (2 bytes), float (4 bytes), then the structure occupies 6 bytes (int + float) memory.
- Union:- It is almost same as structure but the difference is that in this the memory occupied is equal to the the memory occupied by data-type with greatest memory. For example , if we use int (2 bytes) and float(4 bytes) then memory occupied by union is 4 bytes.