Friday 18 January 2013

Enumeration Datatype in C

Enumeration type allows programmer to define their own data type . Keyword enum is used to defined enumerated data type.

enum type_name{ value1, value2,...,valueN };
 
Here, type_name is the name of enumerated data type or tag. And value1, value2,....,valueN are values of type type_name.

By default, value1 will be equal to 0, value2 will be 1 and so on but, the programmer can change the default value as below:

enum cards{
    club=0;
    diamonds=10;
    hearts=20;
    spades=3;
};

Declaration of enumerated variable

Above code defines the type of the data but, no any variable is created. Variable of type enum can be created as:

enum bool{
    false;
    true;
};
enum bool check;
 
Here, a variable check is declared which is of type enum bool.

Example of enumerated type

#include <stdio.h>
enum week 
{
 sunday, monday, tuesday, wednesday, thursday, friday, saturday 
};
 
int main()
{
    enum week today;
    today=wednesday;
    printf("%d day",today+1);
    return 0;
} 
 
Output
4 day
 
 
You can write any program in C language without the help of enumerations but, enumerations helps in writing clear codes and simplify programming.
 

9 comments:

  1. In other words, they go against the grain of thе careers thеir parents hаd.
    I belieνe my exact worԁѕ were "I don't want to be your dirty little secret. 8.

    Take a look at my blog post: pub quiz amsterdam

    ReplyDelete
  2. Now that your tea is hopefully taking effect let's think on that last thought for a moment. - Direct vaginal contact with chemicals, dyes and perfumes. Seek medical or professional help.

    Feel free to surf to my web blog ... chronic yeast infection and pregnancy
    Also see my webpage :: vaginal yeast infection and yogurt

    ReplyDelete
  3. The owner decided after the event to donate half of the proceeds back
    to the students. The game was released on August
    3, and is in stores now, but probably is where it will remain,
    sad to say. Spice things up by including these Halloween-themes recipes:.


    my homepage - kinkos

    ReplyDelete
  4. The only hurdle to accessing this is of course human limitations and the
    fact that the brain does not function solely as a learning
    tool for the human being. I believe my exact words were "I don't want to be your dirty little secret. The decline of the East side blues scene was disheartening, but, it also gave rise to the need for a fresh start, which came in the form of the next blues-only venue, Antone's, founded by the late Clifford Antone, during the summer of 1975.

    My web page brainstormer pub quiz answers

    ReplyDelete
  5. The only hurdle to accessing this is of course human limitations and the
    fact that the brain does not function solely as a learning tool for
    the human being. * Team answer sheets - Basically a grid lined A4 type
    sheet with answer write in numbered boxes and a line on top for the team name.

    Ask your local club to run this for you.

    Feel free to visit my homepage pub quiz answers and questions

    ReplyDelete
  6. In other words, they go against the grain of the careers their parents had.

    Popular prizes include sports tickets, cash and vouchers
    for drinks, food - and dollars off of tabs. The Bull's Head Pub, Bangkok.

    Feel free to visit my weblog: easy pub quiz and answers

    ReplyDelete
  7. These are truly impressive ideas
    in concerning blogging.
    You have touched some good points
    here. Any way keep up wrinting.

    My page affordable college degree online

    ReplyDelete
  8. Way cool! Some very valid points! I
    appreciate you writing this write-up and also the
    rest of the site is extremely good.

    Here is my website :: loan calculator

    ReplyDelete
  9. Hi, I do believe this is an excellent website. I stumbledupon it ;) I will revisit
    yet again since I book-marked it. Money and freedom is the best way to change, may you be rich and continue to guide others.


    My site ... boston tax lawyer

    ReplyDelete