Example of enumeration c in microcontroller programming
Enumeration allows defining a user data types in C language. For this purpose, a #define pre-processor is used, which allows for describing a set of constants. They allow reading and understanding program code much easier as you may define human readable types. For instance, using pre-processor we can define a simple numbers to be as follows: Define is a powerful tool for doing many different definitions in pre-processing stage of source code, but in C language, there is an alternative way of defining a user data types – enumerating using keyword enum: By default, enumeration assigns values from zero and up. You can use enumeration of new types as in following example: Also, you can use an enum to assign special characters to meaningful words like this: enum escapes { BELL = ‘\a’, BACKSPACE = ‘\b’, HTAB = ‘\t’,RETURN = ‘\r’, NEWLINE = ‘\n’, VTAB = ‘\v’ };or enum boolean { FALSE = 0, TRUE }; An advantage of enum over #define is that it has scope, which means that the variable (just like any other) is only visible within the block it was declared. Example: