It is important to note that for the learning of data structures and their implementation effectively and efficiently; in-depth knowledge of c language is essential. In particular, The deep understanding of the pointers and their usage is essential.
This Chapter gives and overview of the features of C language that are essential for the study of data structures.
1.2 ENUMERATED DATA TYPE
Variables of enumerated data type enhance the readability of the program. For example, a payroll program deals with various categories of employees, such as clerks, stenosis, assistants, supervisor, deputy managers and managers. If we decide that code 0 is used for clerks, 1 for stenosis, and so on. Program will not be readable, and later on if the program is to be modified, the task may be difficult if the program is not properly documented. However. However, if we use names of these categories, the program will be more readable.
In C language, you can define your own data type and specify what values a variable of this type can take. The data type defined this way is known as enumerated data type.
For example, since C language dose not support boolean type data (with false and true ), you can create your own as.
enum boolean {false , true };
Here word boolean is called tag name for the user defined data type. Then we can declare variables of this data types of followers
enum boolean flag;
Then we can assign value false or true to variable flag, and also we can compare the value flag with this values.
Internally, these values are represented as 2-byte integer numbers. By default,these number start from 0. Thus the first value in the list is represented by number 0, the second value by 1, and so on. However,we can override these default numbers by specifying the starting number along with the first value of the list.
Variables of enumerated type can also be used in arithmetic and relational expressions. However, the input and output of the variables of enumerated data type is not possible.
You must be logged in to post a comment.