C Language Learning Tutorial eighth chapter-Enumeration, bitwise operations (2)

Source: Internet
Author: User
Tags bitwise numeric value printf

Enumerating the assignment of type variables and using

Enumeration types are used in the following terms:
1. The enumeration value is a constant, not a variable. You cannot assign a value to an assignment statement in a program. For example, the following assignment is made to the elements of the enumeration weekday: Sun=5;mon=2;sun=mon; are wrong.

2. The enumeration element itself is defined by the system as a numeric value that represents an ordinal, defined as 0,1,2 from the 0 start order .... In weekday, the sun value is the 0,mon value of 1, ..., and the SAT value is 6.
Main () {
Enum Weekday
{Sun,mon,tue,wed,thu,fri,sat} a,b,c;
A=sun;
B=mon;
C=tue;
printf ("%d,%d,%d", a,b,c);
}
3. You can only assign an enumeration value to an enumeration variable, and you cannot assign the value of an element directly to an enumeration variable. such as: A=sum;b=mon; is correct. and: A=0;b=1; Is wrong. If you have to assign a value to an enumeration variable, you must use coercion type conversion, such as: A= (enum weekday) 2, meaning that the enumeration element with order number 2 is given an enumeration variable A, which is equivalent to: a=tue; It should also be explained that enumeration elements are not literal constants or string constants, and do not use single or double quotes.
Main () {
Enum body
{a,b,c,d} month[31],j;
int i;
J=a;
for (i=1;i<=30;i++) {
Month[i]=j;
j + +;
if (j>d) j=a;
}
for (i=1;i<=30;i++) {
Switch (Month[i])
{
Case a:printf ("%2d%c\t", I, ' a '); Break
Case b:printf ("%2d%c\t", I, ' B '); Break
Case c:printf ("%2d%c\t", I, ' C '); Break
Case d:printf ("%2d%c\t", I, ' d '); Break
Default:break;
}
}
printf ("\ n");
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.