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.


Related Topics
What is static variable in C
What is pointer in C
What is NULL pointer in C.
Pointer to a function in C.
What are the properties of a register variable in C
What are Tokens in C? what are the different Types of Tokens in C.
What is the use of goto statement in C
What is the relational operators in C
What is assignment operators in C
What is size of void pointer in C