C Language Programming introductory learning five Steps (forwarding)

Source: Internet
Author: User

The author in the process of teaching, hear the students complained most of the sentence is: Teacher, Class I can understand, the book of examples can also see understand, but to their own hands-on programming, but do not know how to start. This behavior occurs for three reasons:

First, the so-called read understand, just very superficial grammar knowledge, and we write the program or software is to solve the problem of the actual need control procedures, if you do not have a deep understanding of the C language statement of the execution process (or process), how can you write a program to solve these practical problems?

Second, the C language programming to solve practical problems, need not only C language programming knowledge, but also need relevant expertise. For example, if you do not know the area formula of a rectangle, even if the C language is better, you can not make a program to ask for the area of the rectangle.

C Language Program design is a very practical course, "paper-on-paper" type of optical not practice is not good at C language. For example, everyone has seen a wonderful bike acrobatic show, if you have never ridden a bike, just listen to the instructor to explain the relevant knowledge, rules, skills, do not say on stage performance, is the road you are afraid not.

The cause of the problem is clear, so how to learn it?

Note: Before using this method to read the relevant content of the C language, to grasp the main points of the relevant knowledge, and then according to the following methods to learn, can achieve understanding, consolidate, improve the C language knowledge and improve the ability of the program.

In the process of program development, the computer debugging program is an indispensable important link. "Three-point programming seven-point debugging", indicating that the program debugging more work than programming. Here is how to debug C program to explain the C language learning methods.

first step, validation exercise  

In this step, you need to follow the program examples in the textbook to input, run the program is correct. In this step basically master the use of C language programming software (including new, open, save, close C program, skilled input, edit C program, the initial memory of the knowledge points of the newly-acquired chapters, develop a good C language programming style).

The easiest mistakes a beginner can make are:

1. There is no difference between the number 1 and the letter L, the letter O and the number 0 in the textbook, which causes the variable undefined error. Another easy point is the English state of the comma, semicolon, parenthesis () double quotation mark "" input into the Chinese state of the comma, semicolon; parentheses (), double quotation mark "" causes illegal character error.

2, C language beginners easy to make grammatical mistakes: the use of undefined variables, identifiers (variables, constants, arrays, functions, etc.) is not case-sensitive, missing "," "{" and "}", "(" and ")", the control statement (selection, branching, looping) is not properly formatted, the call library function does not contain the corresponding header file, Calling a custom function that is not declared in C, calling a function with an argument mismatch, bounding the bounds of an array, and so on.

3. The following two points should be noted when modifying C syntax errors:

(1), because the C language syntax is more free and flexible, so error information positioning is not particularly accurate. For example, if an error occurs on line 10th, if no error is found on line 10th, look for the error and modify it from line 10th.

(2), a statement error may produce several error messages if you modify this error, other errors will disappear. Special Note: In general, the first error message can best reflect the wrong location and type, so debug the program must be based on the first error information to modify, modify, run the program immediately, if there are many errors, to one by one, that is, each modification of an error to run the program once.

C language error message in the form of: (The following example is the Turbo C + + error message, 1)

colon

TD width= ">
error

line number

error content

error

e:\wintc\wint c\frist.c

5

:

function call missing) in Function main

C The form of the error message for the language: (The following example is a visual c++6.0 error message, 2)

Filename

Line number

Colon

Error code

Colon

Error content

E:\wintc\wintc\frist.c

(5)

Error C2143

Syntax error:missing ') ' before '; '

Step two, divert  

In the first step of the input of the C program based on the experimental modification, run a program to see what happens to the program results, analysis of the reasons for the changes in the results, deepen the understanding of the newly learned points. In fact, this is synchronized with the first step to realize "input" to deepen the memory of knowledge, "modify" deepen the understanding of knowledge. Memory and understanding complement each other and promote one another.
For example: The simplest Hello world! program #include "stdio.h" int main () {printf ("Hello world!\n"); return 0; } in the
printf ("Hello world!\n");
In the hello world! changed to your name, run a program, see what changes?
And the procedure of seeking 1+2+3...+100.
#include <stdio.h>
Main ()
{
int i,sum=0;
for (i=1;i<=100;i++) {sum=sum+i;     } printf ("sum=%d\n", sum); }
 
The 1th time to change the for (i=1;i<=100;i++) 100 to 50, run the program, see what changes?
The 2nd time to change the for (i=1;i<=100;i++) i++ to I=i+2, run the program, see what changes?
To find out the reason of the change of the program result, the understanding of C statement is deepened.

The third step, do not look at the textbook to see whether the first two steps of the program can be correctly entered and run.

In this step requires not to read the textbook, even if the program can not be run, see whether it can be corrected to make it work correctly. The aim is to further strengthen the memory and understanding of the first two steps.

Fourth step, enhance the debugging ability of the program

In the textbook each chapter has a C language beginner easy to make mistakes, according to the type of error, the correct program in the textbook to the wrong program, run a program, see the error message prompts, and write down the error message, then the program to correct, run a program. In this way, it is possible to learn the causes of errors in C programming and the ability to modify errors.

Note: Change only one place at a time, the purpose is to show the real cause of the error, avoid changing more than one place at a time, to understand the real cause of the error, remember!!!

Note: On the Machine debugging program to bring a notebook, write down the English error message and the method to solve the error problem, accumulate experience in program debugging, to avoid the same mistakes in programming, remember!!!
For example, the statement in the Hello World program
printf ("Hello world!\n");
A semicolon in a Chinese language;
Run the program and see what the results are?

Debugging program is a very practical thing, light on paper is useless, like swimming athletes only listen to the instructor to explain the demonstration, and do not personally practice, is never learn to swim.

Even in a good programmer to write a program will make mistakes, may be the lowest level of grammatical errors, but he can quickly find errors and correct errors, and we C-language beginners face error prompts, do not know what has happened, how to correct, this ratione materiae difference.

The fifth step, the study of typical C language Program, improve program design ability  

C Language Beginners Encounter the most confusion is: class can understand, the book of examples can also be seen, but to do their own programming, but do not know how to start. The reason for this is that the so-called understanding and understanding is only superficial knowledge of grammar without a deep comprehension of the execution process (or process) of C-language statements.

How can you use this knowledge to solve practical problems if you do not know how the C statements are executed in the computer, according to the instructions of the person (the program written)?

The way to solve the problem is to understand the C language of the various statements of the process (that is, how the computer executes these statements), and then study the ready-made C language Classic program, to understand how others solve problems, to improve their program design capabilities.

C is language studious?

is C language studious? Beginners often ask this question. The answer is very simple, interested in C language, have a strong desire to learn, it is easy to learn. If not interested, then the simple knowledge will not learn. Imagine how several schools now teach students to play games?       The answer is no, but a lot of students will play games, sometimes reach the point of sleepless, playing games to music and not tired, but also often exchange playing the experience of the game, which is the charm of interest. If you are interested in C language, why not learn to play the game experience to learn C language? If so, C language is still difficult to learn?

finally send C language Beginners A word to encourage: first of all to believe that they have the ability to learn C language, and then at all costs to show this ability, you succeed. If you do anything, it is not so.

C Language Programming introductory learning five Steps (forwarding)

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.