Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to learn C language well

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to learn C language well". In the operation of practical cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

One. Learn the operators and operation order of C language well

This is the basis of learning "C programming". The operation of C language is very flexible, the function is very rich, and the type of operation is far more than that of other programming languages. The expression is more concise than other programming languages, such as self-addition, self-subtraction, comma operation and binomial operation, which make the expression simpler, but beginners often find this expression difficult to read. the key reason is that they do not have a complete understanding of operators and operation order. When a variety of different operations form an operation expression, that is, multiple operators appear in one expression, the priority and combination rules of operations are very important.

In learning, as long as we classify them reasonably and find out the differences between them and the operations we have learned in mathematics, it will not be difficult to remember these operations, and some operators will be better remembered after understanding. It is easy to use it in the future, while some can be given up temporarily, and it is not too late to remember when it is time to use it.

First of all, it is necessary to make it clear that operators are classified according to priority. The "C programming" operator can be divided into 15 priorities, from high to low, with a priority of 1 ~ 15. Except for the combination of levels 2, 3 and 14 from right to left, the rest are combined from left to right. it determines the operation order of the same-level operators.

Two. Learn the four program structures of C language well

(1) sequence structure

The programming of sequential structure is the simplest, as long as the corresponding statements are written according to the order of solving the problem, and its execution order is from top to bottom.

For example, a = 3cr b = 5, now exchange the value of aforb, this problem is like exchanging two cups of water, of course, the third cup is used, if the third cup is c, then the correct procedure is:

C = a; a = b; b = c

The result of execution is a = 5, b = c = 3

If you change the order, write as follows:

A = b; c = a; b = c

Then the implementation result becomes a = b = c = 5, which can not achieve the desired goal, and beginners are most likely to make this mistake. The sequence structure can be used independently to form a simple and complete program. The common input, calculation and output three-step program is the sequence structure, such as calculating the area of the circle. The sentence order of the program is to input the radius r of the circle, calculate s = 3.14159*r*r, and output the area of the circle s. However, in most cases, the sequential structure is part of the program, together with other structures to form a complex program, such as the compound statement in the branch structure, the loop body in the loop structure, and so on.

(2) branching structure

Although the program with sequential structure can solve the problems of calculation and output, it can not make judgment and choice. The branch structure should be used for the problems that need to be judged before they are selected. The execution of the branch structure is to choose the execution path according to certain conditions, rather than strictly according to the physical order in which the statements appear. The key of the branch structure programming method is to construct the appropriate branch condition and analyze the program flow, and select the appropriate branch statement according to the different program flow.

The branch structure is suitable for the calculation with conditional judgment such as logic or relational comparison. When designing this kind of program, it is often necessary to draw its program flow chart first, and then write the source program according to the program flow, which separates the program design analysis from the language. it makes the problem simple and easy to understand. The program flow chart is the program execution flow chart drawn according to the problem-solving analysis.

Learning the branch structure should not be confused by the branch nesting, as long as the flow chart is drawn correctly and the function of each branch is clarified, the nested structure is not difficult. Nesting is just a branch that includes branch statements, not new knowledge. As long as you have a clear understanding of two branches, branch nesting is not difficult. Let me introduce some basic branching structures.

① if (condition)

{branching body}

The branch body in this branch structure can be a statement, and "{}" can be omitted or multiple statements, that is, compound statements. It has two branch paths to choose, one is when the condition is true, execute the branch, otherwise jump over the branch, then the branch will not be executed. For example, to calculate the absolute value of x, according to the definition of the absolute value, we know that when x > = 0, its absolute value remains the same, but x

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report