Enumeration Data Type
An enumeration
type is a user defined type that enables the user to define the range of values
for the type. Named constants are used to represent the values of an
enumeration, for example:
enum weekday {monday, tuesday,
wednesday, thursday, friday, saturday, sunday};
weekdaycurrentDay = wednesday;
if(currentDay==tuesday){
// do something
}
The default
values assigned to the enumeration constants are zero-based, so in our example
above monday == 0, tuesday == 1, and so on. The user can assign a different
value to one or more of the enumeration constants, and subsequent values that
are not assigned a value will be incremented. For example:
enum fruit
{apple=3, banana=7, orange, kiwi};
Here, orange
will have the value 8 and kiwi 9.
Boolean Data Type
The Boolean type
can have the value true or false. For example:
boolisEven = false;
boolkeyFound = true;
If a Boolean
value is converted to an integer value true becomes 1 and false becomes 0.
If an integer
value is converted to a Boolean value 0 becomes false and non-zero becomes
true.
No comments:
Post a Comment