C Data Type (enum enumeration) and switch statement

Source: Internet
Author: User
Main. mLessonConditionCreatedbylanouhnon14-7-16.Copyright (c) 2014 vaercly@163.com Chen conglei. Allrightsreserved. # importFoundationFoundation. h Enumeration type is a constructor type that enables a set of Integer constants to list possible definitions

//// Main. m // LessonCondition /// Created by lanouhn on 14-7-16. // Copyright (c) 2014 vaercly@163.com Chen conglei. all rights reserved. // # import Foundation/Foundation. h // The Enumeration type is a constructor type, which enables a set of Integer constants to list the possibilities. // Definition

//

// Main. m

// LessonCondition

//

// Created by lanouhn on 14-7-16.

// Copyright (c) 2014 vaercly@163.com Chen conglei. All rights reserved.

//

# Import

// The Enumeration type is a constructor type that lists the possibilities of an integer constant.

// Define enumeration. Use the keyword enum + name of the enumeration type {enumeration value, multiple enumeration values are separated by commas}. The last semicolon cannot be less

// The Enumeration type maps the identifiers that can be recognized by humans with numbers that can be recognized by computers.

Enum season {

Spring, // spring

Summer = 100, // summer

Autumn, // autumn

Winter // winter

};

Enum company {

Teaching = 801, // teaching part No. 801

Market = 802, // Extension No. 802 of the Marketing Department

Person = 803, // Extension No. 803 of the Personnel Department

Consult = 804 // consult part of the host No. 804

};

Int main (int argc, const char * argv [])

{

@ Autoreleasepool {

Int a = 20, B = 5;

BOOL isTrue = NO;

Printf ("% d \ n", isTrue );

// Relational operators

IsTrue = a> B;

Printf ("% d \ n", isTrue );

// Logical operator logic and (&) logic or (|) logical non (!)

// IsTrue = a | B;

IsTrue =! A;

Printf ("% d \ n", isTrue );

// If statement

// Use of undeclared identifier 'A' variable a is not defined. Solution: Define variable

// Expression result unused the expression result is not used. Solution: define variables and store the expression results

// Unused variable 'B' no variable B is used

// If (condition expression) {statement} in the first structure of the if statement, when the condition of the condition expression is true, execute the statement in braces. Otherwise, execute the statement after the if statement.

If (a> 10 ){

Printf ("% d \ n", );

}

// Exercise 1

Char sex = 0;

// Scanf ("% c", & sex );

If (sex = 'M '){

Printf ("male \ n ");

}

// Enumeration enum + season is the name of the enumeration type

Enum season c = winter;

Printf ("% d \ n", c );

Enum company lanou = teaching;

Printf ("Enter extension number: \ n ");

Scanf ("% d", & lanou );

// Switch matches the value of the expression in parentheses with the constant after the case in the switch. Once the expression is found to be the same, the statement of the case Branch is executed, if no corresponding case is matched, the default branch statement is executed.

// The execution sequence of the default statement is irrelevant to the position. If it does not match the corresponding branch, the default statement is executed.

Switch (lanou ){

Case teaching:

{

Int d = 5;

Printf ("Connect Teaching Department \ n ");

Break; // end the current branch, jump out of the switch, and execute the statement after the switch

} // If variables are defined in the case Branch, you must add {}

Case market:

Printf ("connect to the marketing department \ n ");

Break;

Case person:

Printf ("connect to the Personnel Department \ n ");

Break;

Case consult:

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.