C language programming notes (Zhejiang University)

Write in front

The notes taken during class have no reference value and only record what is useful to you.

chap1 programming and C language

Computer and programming language

Tossing and dividing:
find the greatest common divisor between two numbers

int u = 32;
int v = 26;
while (v != 0)
{
    
    
	int temp = u % v;
	u = v;
	v = temp;
}
printf("%d",u);

algorithm:

  1. If v is equal to 0, the calculation ends, u is the greatest common divisor;
  2. If v is not equal to 0, then calculate the remainder of u divided by v so that u is equal to v, and v is equal to that remainder;
  3. Back to the first step.

Enumeration
dichotomy

Program execution

  • Explanation:
    With the help of a program, that program can try to understand your program, and then execute it with the help of your requirements (there are some special computing capabilities, eg, you can modify the source code while running)
  • Compilation:
    With the help of a program, just like a translation, you can translate your program into a program written in a language that the computer really understands—machine language—and then the program in the machine language department can be directly executed (with definite computing performance) , The running speed of the same program is fixed)
    ps. Any language can be interpreted and executed as well as compiled and executed.
    C language is generally compiled and executed.

C language

  • Modern programming languages ​​have very little grammatical differences
    • Almost all C-like languages
  • Language ability/applicable field is mainly determined by
    -library
    • Traditionally determined

Fortran language is the first high-level programming language in human history.

Among high-level languages, C language appears to be a relatively low-level language.

Calculation

variable

Assignment
a = b
represents a relationship in mathematics, that is, the value of a and b are the same, which is static ;
in programming, a = b means that the computer is required to assign the value of b to a, which is an action and dynamic of.

The C99 standard allows variables to be defined anywhere in the code.

Write the constant in the program directly , called the direct quantity , or the magic number (magic number) ei, you don’t know what this number represents

const is a modifier .

expression

Operator (operand) is also called operand, refers to the value involved in the operation, this value may be a constant, it may be a variable, or it may be the return value of a method

Symbolic priority
ps monocular: only one operator

priority Operator Calculation Binding relationship distance
1 + Monocular unchanged Right to left a*+b
1 - Single item negative Right to left a*-b
2 * Multiply From left to right a*b
2 / except From left to right a/b
2 %
3
3
4

Guess you like

Origin blog.csdn.net/One_Nation_Lee/article/details/109318752