Base c: Boolean type (BOOL) relational operator switch

Source: Internet
Author: User
Tags logical operators

Boolean type (BOOL): is a type of data that is not true or false.

Variables of type BOOL have only two values: YES (1) or NO (0).
In the C language, it is considered that a non 0 is true.

Relational operators
logical operators, with or not (&,|,!) Logic and: Simultaneous establishment of logic or: the same false is false logic is not: The result of the expression to reverse
Three structure of the program: sequential structure, branching structure, cyclic structure
If statement
Note: If a conditional expression cannot be added after a semicolon, the statement will be executed regardless of whether the conditional expression is valid



The second form of an if statement
if (conditional expression) {statement 1;} else {statement 2;}

Conditional operator
Three-mesh operator
Format: conditional expression. Expression 1: Expression 2//when the conditional expression is set up, the value of the condition 1 is executed, and the value of the execution condition 2 is given as follows:
max = (a>b)? A:B; Take the larger one in the variable A, B, and assign it to the variable max



Enum type enum
Switch statement
//
A multiple-spoke statement that determines which branch to execute by judging the value of an integer expression.
Switch often used with case
Switch syntax format
//
Switch (integer expression) {
Case value 1: statement 1;
break;//Case Value 2: statement 2;
Break
}


int A;
printf ("Enter number \ n");
scanf ("%d", &a);
Switch (a) {
Case 1:printf ("Spring \ n");
Case 2:printf ("Summer \ n");
Case 3:printf ("Fall \ n");
Case 4:printf ("Winter \ n");
default:printf ("input error, reenter \ n"); break;

Break is the end of the whole loop body, continue is the end of a single cycle


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.