Home > Software engineering >  Enumeration syntax
Enumeration syntax

Time:01-31

Can someone please explain to me which part is what in this:

enum bb { cc } dd;

I understand that enum bb is the name of the enumeration and that { cc } is its enumerator, but I have no clue what dd is.

CodePudding user response:

enum bb
{
  cc
} dd;
  1. bb - enum tag.
  2. cc - enumerator constant. As it is first and it does not have an expicity defined value it will be zero (0);
  3. dd - variable of type enum bb

It can be written as:

enum bb
{
  cc
};

enum bb dd;

CodePudding user response:

It defines dd as a variable of the type enum bb. Take a look at Enumerations It behaves just like when you're defining normally

#include <stdio.h>
int main()
{
    enum bb { cc, ee } dd  = cc; // dd is now 0
    dd = ee; // dd is now 1
    printf("%d", dd); 
}

Link.

  • Related