C Programming
C++ Programming
The Difference Between

What is difference between C enum and C plus plus enum?

User Avatar
Wiki User
February 10, 2008 9:57AM

In C++, enum signifies a slightly stronger type than in C.

For example, in C, one could write:

enum Direction { UP, DOWN };

Direction d = 1;

In C++, this would be illegal, only UP or DOWN can be assigned to a variable of type Direction, though there is still implicit casting to integer, so one could still write:

int i = UP;

Another difference has to do with the way variable are declared in general in C++. In C, once the enum was declared as above, declaring variables of type Direction would have to be done through the enum keyword, like this:

enum Direction d = UP;

In C++, the name "Direction" becomes a type in itself, so you can write:

Direction d = UP;