C language base expression, relational operator, logical operator, bitwise operator, data range, branch structure (If...else, switch...case)

Source: Internet
Author: User
Tags bitwise bitwise operators

1. Expression: The expression is judged to have no result (value), the simplest expression is a constant or variable, such as: A, A, 3 + 1, a + B, a + 5 are expressions

2.BOOL (Boolean) data type: In addition to the basic data types in the C language, there are boo data types, as well as some other data types, such as custom struct data types

The bool data type is a data type that represents a non-true-to-false value, with a Boolean variable that has only Yes and no two values.  Yes indicates that the expression structure is true, and conversely, no indicates that the result of the expression is false (in C, not 0 is true), the bool type is used primarily with the branching structure or the loop structure to determine whether to execute an IF statement or else statement, or to determine if the loop body is to be executed. #define YES 1 when the computer is recognized, the Yes is replaced by 1, #define NO 0 when the computer is recognized, no is replaced by 0

3. Relational operator: >=, <, <=, = =,! =

Relational operators are mainly used for comparison operations, the results of comparison are only true and false two cases, the result value is stored with the BOOL type variable. Note: To determine whether two numbers are equal, use = = (double equals)

4. Logical operator:&& (logic and), | | (logical OR),! (Logical non)

An expression consisting of logical operators, and the result is not true or false.

&&: The result of the entire logical expression is true when the expression on both sides of the operator is true

The result of the entire logical expression is false when the expression on both sides of the operator is false

!: Reverse the value of an expression. If the value of an expression is 0 (false), the inverse value is not 0 (true); When the value of an expression is not 0 (true), the inverse is 0 (false)

5. Bitwise operators: & (Bitwise AND), | (bitwise OR), ^ (bitwise XOR), ~ (bitwise NON)

Bitwise operators:

//Bitwise AND &: The same is 1, then 1, otherwise 0, for one to clear 0

int a = 4 & 6;

printf ("%d\n", a);

bitwise OR |: The same is 0, or 0, otherwise 1, which is reserved for one

A = 4 | 6;

printf ("%d\n", a);

Bitwise XOR ^: same as 0, different 1

A = 4 ^ 6;

printf ("%d\n", a);

//bitwise NON ~: If it is a signed number, the binary highest bit represents the sign bit , 1 for negative , and 0 for positive

//data is stored in the form of complement in memory , positive complement is positive , negative complement is absolute minus 1

6. A byte represents a 8-bit binary number

range of values for data types:

A. unsigned:

Char 0 ~ 2^8-1

Short 0 ~ 2^16-1

int 0 ~ 2^32-1

B. signed:

Char-2^7 ~ 2^7-1

SHORT-2^15 ~ 2^15-1

int-2^31 ~ 2^31-1

*/

7. If...else ... Relatively simple, it is not remembered. Switch...case Branching structure

int number = 0;

printf(" Please enter an extension number (801: Teaching Department, 802: Consulting Department, 803: Finance Department, 804: Security Section, 805: marketing Department): \ n");

scanf ("%d", &number)

Switch (number) {

Case 801:

Case 809://The result of the output when number = 801 or 809 is the teaching department

printf (" teaching department \ n");

Break;//break End the current branch, exit switch, execute the statement after switch

the representation after case 802://case must be a constant, or a constant expression

{int a = 10;} if you want to define variables in the case branch, Be sure to add braces

printf (" Consulting department \ n");

Break

Case 803:

printf (" Finance department \ n");

Break

Case 804:

printf (" Security section \ n");

Break

Case 805:

printf (" marketing department \ n");

Break

executes the default statement when the corresponding case branch is not found (matched to)

Default

printf (" who to look for");

Break

}

Note: the representation after a case must be a constant, or a constant expression. If you want to define a variable in a branch of the box, be sure to add braces

C language base expression, relational operator, logical operator, bitwise operator, data range, branch structure (If...else, switch...case)

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.