Explain enumerated constants, C/C++ Programming

Assignment Help:

Enumerated Constants

Enumerated constants enable the creation of new types and then explain variables of these types so that their values are restricted to a set of possible values.

e.g.

 enum Colour{RED, BLUE, GREEN, WHITE, BLACK};

Colour is the name of an enumerated data type. It makes RED a symbolic constant with the value 0, BLUE a symbolic constant with the value 1 and so on.

- Each enumerated constant has an integer value. If the program doesn't specify or else, the first constant will have the value 0, the remaining constants will count up by 1 as compared to their predecessors.

- Any of the enumerated constant can be initialised to have a particular value, though; those that are not initialised will count upwards from the value of previous variables.

e.g.

enum Colour{RED = 100, BLUE, GREEN = 500, WHITE, BLACK = 1000};

The values assigned will be RED = 100,BLUE = 101,GREEEN = 500,WHITE = 501,BLACK = 1000

 

  • You can explain variables of type Colour, but they can hold only one of the enumerated values. In our case RED,BLUE,GREEEN,WHITE,BLACK .
  • You can declare objects of enum types.

 


Related Discussions:- Explain enumerated constants

Program to compute quadratic polynomial, Write a function that computes f(x...

Write a function that computes f(x) for a quadratic polynomial in x, such as the one in assignment 3. Use the function to plot f(x) from -10 to +10.

What are the differences among a struct in c & in c++?, A: In C++ a struct ...

A: In C++ a struct is alike to a class except for the default access specifier( refer to other question in the document). In C we ought to include the struct keyword while declarin

When should i use references, A: Use references when you can use, and use p...

A: Use references when you can use, and use pointers when you have to. References are generally preferred over pointers whenever you don't require "reseating". Usually this mean

Radix, a popular joke among computer is to say............

a popular joke among computer is to say............

Code for design software, In this project, you will write a software for th...

In this project, you will write a software for the Registrar's office of a university called YouOIT to maintain information about students and courses at the university. The reg

Define external storage class - computer programming, Define External Stora...

Define External Storage Class - computer programming? When a variable is declared outside a function the storage is permanently assigned to it and its storage class is 'extern'

Palindorme, program coding for the conversion of string to a palindrome

program coding for the conversion of string to a palindrome

How, how to program?

how to program?

C++ program, Receive 3 numbers and display them in ascending order from sma...

Receive 3 numbers and display them in ascending order from smallest to largest ed#

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd