Enum and Void Data Type in C

Interview Questions

  • What is enum data type in C.
  • What is void data type in C.

What is enum data type in C

Enumeration Types are a way of creating your own Type in C. It is a user-defined data type consists of integral constants and each constant is given a name. The keyword used for an enumerated type is enum. The enumerated types can be used like any other data type in a program.
Here is the syntax of declaring an enum

enum identifier{ value1, value2,...,valueN };

For Example :

enum days{ Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};

Now any variable of enum days can take any one of the seven values.
enum days holiday = Sunday;
Here, holiday is a variable of data type enum days and is initialized with value Sunday.

What is void data type in C

The void data type is an empty data type that refers to an object that does not have a value of any type. Here are the common uses of void data type. When it is used as a function return type.

void myFunction(int i);

Void return type specifies that the function does not return a value.

When it is used as a function’s parameter list:

int myFunction(void);

Void parameter specifies that the function takes no parameters.

When it is used in the declaration of a pointer variable:

void *ptr;

It specifies that the pointer is “universal” and it can point to anything. When we want to access data pointed by a void pointer, first we have to type cast it.