ENUMERATED, typedef
ENUMERATED DATA TYPES

• An enumeration consists of a set of named integer
constants.
• An enumeration type declaration gives the name of the
(optional) enumeration tag and defines the set of named
integer identifiers (called the "enumeration set,"
"enumerator constants," "enumerators," or "members").
A variable with enumeration type stores one of the
values of the enumeration set defined by that type.
• Variables of enum type can be used in indexing
expressions and as operands of all arithmetic and
relational operators.
• Enumerations provide an alternative to the #define
preprocessor directive with the advantages that the
values can be generated for you and obey normal
scoping rules.
•
•
•
•
•
•
•
•
•

ENUMERATED DATA TYPES

enum identifier { enumerator-list }
Example
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
void main()
{
clrscr();
enum month { jan = 1, feb, mar, apr, may, jun, jul,
aug, sep, oct, nov, dec };
•
printf("%d“,feb);
•
getch();
• }
typedef

• A typedef declaration lets you define your own
identifiers that can be used in place of type specifiers
such as int, float, and double.
• A typedef declaration does not reserve storage.
• The names you define using typedef are not new data
types, but synonyms for the data types or combinations
of data types they represent.
• The name space for a typedef name is the same as other
identifiers.
• The exception to this rule is if the typedef name
specifies a variably modified type. In this case, it has
block scope.
• typedef int LENGTH;
• LENGTH length, width, height;

6 enumerated, typedef

  • 1.
  • 2.
    ENUMERATED DATA TYPES •An enumeration consists of a set of named integer constants. • An enumeration type declaration gives the name of the (optional) enumeration tag and defines the set of named integer identifiers (called the "enumeration set," "enumerator constants," "enumerators," or "members"). A variable with enumeration type stores one of the values of the enumeration set defined by that type. • Variables of enum type can be used in indexing expressions and as operands of all arithmetic and relational operators. • Enumerations provide an alternative to the #define preprocessor directive with the advantages that the values can be generated for you and obey normal scoping rules.
  • 3.
    • • • • • • • • • ENUMERATED DATA TYPES enumidentifier { enumerator-list } Example #include <stdio.h> #include <conio.h> #include <alloc.h> void main() { clrscr(); enum month { jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec }; • printf("%d“,feb); • getch(); • }
  • 4.
    typedef • A typedefdeclaration lets you define your own identifiers that can be used in place of type specifiers such as int, float, and double. • A typedef declaration does not reserve storage. • The names you define using typedef are not new data types, but synonyms for the data types or combinations of data types they represent. • The name space for a typedef name is the same as other identifiers. • The exception to this rule is if the typedef name specifies a variably modified type. In this case, it has block scope. • typedef int LENGTH; • LENGTH length, width, height;