Thu Nov 13, 2008 2:38 pm
/* C enumerate type creates symbolic names. The names have integer
values. */
#include <stdio.h>
/* This assigns the names Sun through Sat to the values 0 through 6.
They are constants, and cannot be changed. It also defines the
tag daynames which can be used to declare a variable of this type. */
enum daynames { Sun, Mon, Tue, Wed, Thu, Fri, Sat};
/* This just defines the names */
enum {SEC = 1, MIN = 60, HOUR = 60*60, DAY = 24*60*60};
int main()
{
/* Declare a variable of type enum daynames. It is really
just an integer, of some size picked by the implementation
large enough to hold all the enumeration values. */
enum daynames today;
/* This defines some names, each one taking the value one greater
if than the last, if not given a specific value. The variable
dd can hold any of the enumeratoin values. */
enum { DINK, DANK = 5, DUNK, DONGLE = 4, DANGLE, DROP } dd;
int n;
/* Days of the week. These are just integer codes. */
for(today = Mon; today <= Fri; ++today)
printf("%d ", today);
putchar('\n');
/* Using the second value constants. */
printf("Three days, four hours, and 28 minutes is %d seconds.\n",
3*DAY + 4*HOUR + 28*MIN);
/* Enum type variables are just integers. Enum values are just
integers. */
dd = 2;
printf("%d %d %d %d %d %d %d\n", DINK, DANK, DUNK, DONGLE, DANGLE,
DROP, dd);
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.