Enumerations
You can use the enum keyword to define enumerations as follows:
enum <typeName>
{
<value1>,
<value2>,
<value3>,
...
<valueN>
}
Next, you can declare variables of this new type as follows:
<typeName> <varName>;
You can assign values using the following:
<varName> = <typeName>.<value>;
you can also do enumeration like below,
enum <typeName> : <underlyingType>
{
<value1> = <actualVal1>,
<value2>,
<value3> = <value1>,
<value4>,
...
<valueN> = <actualValN>
}
Structs
The struct(short for structure) is just that. That is, structs are data structures are composed of several pieces of data, possibly of different types. They enable you to fefine your own types of variables based on this structure.
You can use the enum keyword to define enumerations as follows:
enum <typeName>
{
<value1>,
<value2>,
<value3>,
...
<valueN>
}
Next, you can declare variables of this new type as follows:
<typeName> <varName>;
You can assign values using the following:
<varName> = <typeName>.<value>;
you can also do enumeration like below,
enum <typeName> : <underlyingType>
{
<value1> = <actualVal1>,
<value2>,
<value3> = <value1>,
<value4>,
...
<valueN> = <actualValN>
}
Structs
The struct(short for structure) is just that. That is, structs are data structures are composed of several pieces of data, possibly of different types. They enable you to fefine your own types of variables based on this structure.
Comments
Post a Comment