Page 13 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 13

Fundamentals of Data Structures




                    Notes          1.2.3 C Character Types

                                   C uses char type to store characters and letters. However, the char type is integer type because
                                   underneath C stores integer numbers instead of characters.
                                   In order to represent characters, the computer has to map each integer with a corresponding
                                   character using a numerical code. The most common numerical code is ASCII, which stands for
                                   American Standard Code for Information Interchange. Table 1.5 illustrates the ASCII code:
                                                              Table 1.5: ASCII Code Chart


















                                          Example: The integer number 65 represents a character A in upper case.
                                   In C, the char type has 1-byte unit of memory so it is more than enough to hold the ASCII codes.
                                   Besides ASCII code, there are various numerical codes available such as extended ASCII codes.
                                   Unfortunately, many character sets have more than 127 even 255 values. Therefore, to fulfill
                                   those needs, the Unicode was created to represent various available character sets. Unicode
                                   currently has over 40,000 characters.

                                   1.2.4 C Enum

                                   Enum defines enumeration types, to enhance your code readability.
                                   C provides developers with special types called enumerated types or enum to declare symbolic
                                   names that represent integer constants. Its main purpose is to enhance the readability of the
                                   code. An enumeration consists of a group of symbolic integers.


                                          Example: We can declare an enumeration for colors as follows:
                                   enum color {red, green, blue};
                                   In the example given above:

                                       enum is the keyword to declare a new enumeration type
                                       color is the tag name that you can use later as a type name.

                                       !

                                     Caution  The tag name must be unique within its scope. This tag name is also optional so
                                     you can omit it.
                                       Inside the curly brackets {} is a set of named integers. This set is also known as enumeration
                                       constants, enumeration sets, enumerators or just members.





          6                                 LOVELY PROFESSIONAL UNIVERSITY
   8   9   10   11   12   13   14   15   16   17   18