UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What is meant by “enum” in C?

Asked by Last Modified  

Follow 7
Answer

Please enter your answer

IT Professional Trainer with 21 years of experience in education field

An enum is a keyword in C language, it is an user defined data type. All properties of integer are applied on Enumeration data type It work like the Integer.
Comments

Trainer

enum The enum type specifier is short for "enumerated data". The user can define a fixed set of words that a variable of type enum can take as its value. The words are assigned integer values by the compiler so that code can compare enum variables. Consider the following code example: #include stdio.h /*...
read more
enum The enum type specifier is short for "enumerated data". The user can define a fixed set of words that a variable of type enum can take as its value. The words are assigned integer values by the compiler so that code can compare enum variables. Consider the following code example: #include stdio.h /* To shorten example, not using argp */ int main () { enum compass_direction { north, east, south, west }; enum compass_direction my_direction; my_direction=west; return 0; } This example defines an enumerated variable type called compass_direction, which can be assigned one of four enumerated values: north, east, south, or west. It then declares a variable called my_direction of the enumerated compass_direction type, and assigns my_direction the value west. Why go to all this trouble? Because enumerated data types allow the programmer to forget about any numbers that the computer might need in order to process a list of words, and simply concentrate on using the words themselves. It's a higher-level way of doing things; in fact, at a lower level, the computer assigns each possible value in an enumerated data type an integer cconstant -- one that you do not need to worry about. Enumerated variables have a natural partner in the switch statement, as in the following code example. #include stdio.h enum compass_direction { north, east, south, west }; enum compass_direction get_direction() { return south; } /* To shorten example, not using argp */ int main () { enum compass_direction my_direction; puts ("Which way are you going?"); my_direction=get_direction(); switch (my_direction) { case north: puts("North? Say hello to the polar bears!"); break; case south: puts("South? Say hello to Tux the penguin!"); break; case east: puts("If you go far enough east, you'll be west!"); break; case west: puts("If you go far enough west, you'll be east!"); break; } return 0; } In this example, the compass_direction type has been made global, so that the get_direction function can return that type. The main function prompts the user, Which way are you going?, then calls the "dummy" function get_direction. In a "real" program, such a function would accept input from the user and return an enumerated value to main, but in this case it merely returns the value south. The output from this code example is therefore as follows: Which way are you going? South? Say hello to Tux the penguin! As mentioned above, enumerated values are converted into integer values internally by the compiler. It is practically never necessary to know what integer values the compiler assigns to the enumerated words in the list, but it may be useful to know the order of the enumerated items with respect to one another. The following code example demonstrates this. #include stdio.h /* To shorten example, not using argp */ int main () { enum planets { Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto }; enum planets planet1, planet2; planet1=Mars; planet2=Earth; if (planet1 > planet2) puts ("Mars is farther from the Sun than Earth is."); else puts ("Earth is farther from the Sun than Mars is."); return 0; } The output from this example reads as follows: Mars is farther from the Sun than Earth is. read less
Comments

In computer programming, an enumerated type (also called enumeration, enum, or factor in the R programming language, and a categorical variable in statistics) is a data type consisting of a set of named values called elements, members, enumeral, or enumerators of the type.
Comments

Primary Teacher

In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to the simple String or int constants used in many older APIs to represent sets of related items. Enumeration (or enum) in C. Enumeration...
read more
In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to thesimpleString or int constants used in many older APIs to represent sets of related items. Enumeration (orenum) inC. Enumeration (orenum) is a user defined data type inC. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.enumState {Working= 1, Failed = 0}; The keyword 'enum' is used to declare new enumeration types inCandC++. read less
Comments

Primary Teacher

In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to the simple String or int constants used in many older APIs to represent sets of related items. Enumeration (or enum) in C. Enumeration...
read more
In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to thesimpleString or int constants used in many older APIs to represent sets of related items. Enumeration (orenum) inC. Enumeration (orenum) is a user defined data type inC. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.enumState {Working= 1, Failed = 0}; The keyword 'enum' is used to declare new enumeration types inCandC++. read less
Comments

Primary Teacher

In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to the simple String or int constants used in many older APIs to represent sets of related items. Enumeration (or enum) in C. Enumeration...
read more
In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to thesimpleString or int constants used in many older APIs to represent sets of related items. Enumeration (orenum) inC. Enumeration (orenum) is a user defined data type inC. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.enumState {Working= 1, Failed = 0}; The keyword 'enum' is used to declare new enumeration types inCandC++. read less
Comments

Primary Teacher

In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to the simple String or int constants used in many older APIs to represent sets of related items. Enumeration (or enum) in C. Enumeration...
read more
In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to thesimpleString or int constants used in many older APIs to represent sets of related items. Enumeration (orenum) inC. Enumeration (orenum) is a user defined data type inC. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.enumState {Working= 1, Failed = 0}; The keyword 'enum' is used to declare new enumeration types inCandC++. read less
Comments

Primary Teacher

In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to the simple String or int constants used in many older APIs to represent sets of related items. Enumeration (or enum) in C. Enumeration...
read more
In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to thesimpleString or int constants used in many older APIs to represent sets of related items. Enumeration (orenum) inC. Enumeration (orenum) is a user defined data type inC. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.enumState {Working= 1, Failed = 0}; The keyword 'enum' is used to declare new enumeration types inCandC++. read less
Comments

Primary Teacher

In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to the simple String or int constants used in many older APIs to represent sets of related items. Enumeration (or enum) in C. Enumeration...
read more
In programming Enum is a keyword defined for Enumeration a new data type. Type safe enumerations should be used liberally.In particular, they are a robust alternative to thesimpleString or int constants used in many older APIs to represent sets of related items. Enumeration (orenum) inC. Enumeration (orenum) is a user defined data type inC. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.enumState {Working= 1, Failed = 0}; The keyword 'enum' is used to declare new enumeration types inCandC++. read less
Comments

Linux Expert

It's a user defined data type consisting of a set of named values called elements, members or enumerators of the type. It gives meaningful names to constants. Check the C standard for more
Comments

View 9 more Answers

Related Questions

What is the benefit of using an enum rather than a #define constant?
#define is a symbolic constant. symbolic constants are uppercase letters. symbolic constants above the main() function. symbolic constants are not terminated with semicolon. symbolic constants must define using #define preprocessor directive.
Basundhara
0 0
7
what are type qualifiers in c language
The type qualifiers/modifiers in C language are used to alter the meaning of basic data types. These can be divided into 3 categories: 1. Size modifiers a. short (default) b. long 2. Sign modifiers a....
Mahesh
What is the use of getch(); in the end of c program
getch() is used to hold the console(output) window on the screen after the whole program run is completed till the user enters a key from keyboard. However, the character entered is not displayed on screen....
Priyanka
What is a macro, and how do you use it?
A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look...
Sandeep

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Be prepared to get trained--init
Before starting the training,students must be mentally prepared for acceptance of new knowledge. Students must attend training with open minded forgetting the position they are working.This will help...
S

Smartnub Softsolutions

0 0
0

PRACTISE makes you PERFECT ; ; ; There is no SUBSTITUTE for HARD WORK ;;;;Breathe SUCCESS like OXYGEN
Proper Planning ( reg what portions to be covered today) revising today's class portions & clarifying doubts solving Maths problems regularly ,noting down formulae separately trying to understand...

Why we need to learn Programming languages?
Language is medium for communication. If two parties like to communicate or exchange the thoughts they must know a language. Language should be understandable by both the Parties. For example A wants to...

Why Indexing Should Start From Zero In Array ?
Why numbering should start at zero? To denote the subsequence of natural numbers 2, 3, ..., 12 without the pernicious three dots, fourconventions are open to usa) 2 ≤ i < 13b) 1 < i ≤ 12c)...

Variables
Variables in C Language:A variable is a name that may be used to store a data value. Unlike constant, variables are changeable, we can change value of a variable during execution of a program. A programmer...

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more