C Language Structure

About C language structure, we may think about to discuss it through 4 of aspects such as Sequence structure, routine structure, function and operation symbols. For newbies, I will state below according to these 4 aspects. The first, it is about Sequence structure.

Syntactic Structure

 

  • Sequence structure

Sequence structure of the program design is the simplest, as long as in the order to solve the problem to write the corresponding statement on the line, its execution sequence is top-down, in turn.

 

For example, a = 3, b = 5, now exchange a and b values, this problem is like exchange of two cups of water, so have to use the third cup, if the third cup is c, then the correct program is: c = a; a = b; b = c; the result is a = 5, b = c = 3.

 

If you change the sequence, write: a = b; c = a; b = c; then the execution results become a = b = c = 5, can not achieve the desired purpose, the beginners are most likely to make this mistake.

 

Sequence structure can be used independently to form a simple complete program, the  program as three-step such as common input, calculation and output is the Sequence structure. In most cases, the Sequence structure is part of the program and forms a complex program with other structures together.

 

  • Selective structure

Sequence structure programs can solve the problems of calculation and output, but they can not be judged and chosen again. For the issues have to judge and choose at the first, exactly the selective structure should be used. The execution of the selective structure is to select the execution path according to certain conditions, rather than strictly according to the physical sequence in which the statement appears.

 

The key to program design method of selective structure is to construct appropriate branch conditions and analyze program flow, and select appropriate selective statements according to different program flow.

 

  • Cycle structure

Cycle structure (Loop structure) can reduce the workload of repetitive writing of source program to describe the problem of repetitive execution of a segment of algorithm. This is the program structure that can give full play to computer expertise in programming. In C language, there are four kinds of loops: goto loop, while loop, do while loop and for loop.

 

It is particularly important to note that should contain the statements that tend to end in the loop body (i.e. changes in the value of the loop variable), otherwise it may become a dead loop. This is a common mistake for beginners.

 

 

Programming and Code Information.

Click Here for More Post.

 

Bookmark the permalink.

Comments are closed.