# Re-learn the C language---05 operators, expressions, and statements

Source: Internet
Author: User
Tags arithmetic

I. Introduction of the Cycle

Instance Program

/*shoes1.c--the size of a pair of shoes into inches */
#include <stdio.h>
#define SCALE 0.325

int main (void)
{
Double shoe,foot;
printf ("Shoe size (men's) foot length\n");
shoe = 3.0;
while (shoe<18.5)/*while loop */
{/* Code start */
printf ("%10.1f%15.2f inches\n", shoe,foot);
shoe = shoe+1.0;

}/* Code End */
printf ("If the shoe fits. Wear it\n ");
return 0;
}

Explain how the while loop works:

1, when the first time to reach the while loop, check whether the conditions inside the parentheses are true, that is shoe<18.5?, if the condition is true, execute the next sentence, then print the result, and finally execute the shoe=shoe+1;

2. Continue to return while part to Judge shoe<18.5? The value of shoe is 4.0, because shoe in the code block has been added 1.0;

3, continue to return to the while part of the judgment, know that the value of shoe is greater than 18.5, will no longer execute while part of the code, that is, while () parentheses inside the condition returns the result is False, skip the loop, execute the following statement.

The above example is a circular demonstration, the computer is doing countless loops, which is difficult for us to complete the manual work.

Second, the basic operator

C uses operators to represent arithmetic operations

1. Assignment Budget symbol: =

In C (including many programming languages), Symbol = does not mean "equal", but an assignment operator.

For example: height = 1.73;

The left side of the symbol = is a variable name, the right is the value assigned to the variable, the direction is from right to left.

Several terms: data object, left value, right value, and operand

A data object---is a term used to refer to a data store for storing values.

An lvalue---the name or expression used to identify a particular data object.

Rvalue---can be assigned to the amount of modifiable lvalue

The operand---the object that the operator operates on.

So that the values on both sides of it are added together.

3. Subtraction Operator:-

Subtract the number that follows it from the number in front of it

4. Symbol operators:-and +

The minus sign can be used to indicate or change an algebraic symbol of a value

5. Multiplication Operator: *

6. Division Operator:/

7, Operator Precedence:

8. Other operators: self-increment (+ +) and auto-subtract (--)

Prefix: Appears in front of the variable it is acting on, first self-increment or decrement, and then participates in the arithmetic

Suffix: Appears at the back of the variable it acts on, first doing the operation, then the self-increment

`#include <stdio.h>int main (void) {int a =1,b=1;int q,r;int aplus,plusb;aplus = a++;/* suffix */plusb = ++b;/* prefix */q = 2*++a; r = 2*b++;p rintf ("a aplus b plusb\n");p rintf ("%1d%5d%5d%5d%5d%5d\n", a,aplus,b,plusb,q,r); return 0; }`

Re-learn the C language---05 operators, expressions, and statements

Related Keywords:

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.