Enumerated type in C

enum:

         enum allows user to define their own datatype.Keyword enum is used to create user defined datatype. enum maps the values to integers.Let us consider the example1, color is an enumerated type allows three values red,green and blue.


enum-in-c

Output of above program is 0,1,2 which shows that the enum maps the values to integers.Consider next example program2.


enum-in-c




















In this program2 red,green and blue are assigned with 10,20 and 30. If we print the values as shown 
above then it will print 10 20 30 as output without any error.Let us assign float values to these enum values as shown example3.Then it'll generate an error "Constant Expression Required".Only integer values are allowed for enum

enum-in-c
Frenzz try these programs with various inputs and comment below if any new thing observed.

Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment