Also tell C language

xiaoxiao2021-03-06  53

Talking to the C language, I think all the friends who have learned it have such a feeling, that is, "Let me have a happy time." Happy, C language function is very powerful, wide application, once, you It is possible to talk to others, "I am a computer master!", And later, if you have learned another language, you will be easy. Anxious thing is that C language is like "Shaolin Martial" generally profoundly, too difficult to learn. In fact, on the author thinks that C is not "Difficult (difficult)", you can clarify your thoughts, master its essence, then self-study C language is very easy and happy. Today I will talk with everyone how to learn C language or learn what aspects of C language should start.

Understand some basic knowledge

One. C language background

In touch with personal touch, no matter which language is learned, you should first understand the background of your language, you can also say its development history.

The C language is a kind of advanced program language, and its predecessor is "algol". Its founder is Brown W. Kanihan and Dennis M. Lie. The C language has a large limit because it can only be used on UNIX systems. However, with the advancement of science and technology, the development of computer industries, C language gradually detachard from UNIX. In 1987, the US Standardization Association developed the international standard of C language, referred to as "ANSI C", which will become a widely used program language. There is a lot of advantages in C language, and there is the following four points:

1. There is an advantage in high-grade language and low-level languages, which belongs to an intermediate language.

2. It is a structured programming language, which is very suitable for structured programming.

3. There are richer data types, operators, and function for use.

4. Directly deal with memory, make modifications, edit other programs and documents to make it easy, simple.

two. Two different learning methods

The author has learned a lot of programming languages, such as: C, C (expstration of C language), QBasic, VB (Basic visualization), JavaScript, JScript, VBScript, Java, ASP, FoxPro, Perl, etc., it is actually The advanced program language is divided into two major languages. All the way is the main program language in C, for example: JavaScript, Java, etc., such languages ​​are extremely similar to the call of functions, the writing of the program statement, and the control of the loop is extremely similar. Another way is a program language headed by Basic, such as FoxPro, VBScript, etc., such languages ​​also have similar function calls, program statement writing, and loop control, but are different from C language. Therefore, if you are from QBasic, it is best to wash the brain before learning C language, don't use the method of learning Basic and the idea of ​​thinking.

Speaking here, I think everyone must have a sense of sensibility to the C language! Let us subliminate it again, all-round contact it. Learning C language must start from the following four points, that is, as long as you can master this four points, then basically have a great effort.

Intimate contact C language

One. input Output

The input output of the C language is very strict, perhaps we can do not care about this problem in other programs, but we must completely understand it. Due to the limited space, the author cannot talk about it, interested friends can refer to the editor of Mr. Tan Haqiang, professor of the famous proceedings, and the second edition of the C program design published by Tsinghua University Press. However, there are still a few more about it. 1. Input of two-dimensional floating point count

The input of the two-dimensional floating point count (ie: assigning the two-dimensional floating point count) to the two-dimensional floating point counts, there is no detail in many professional books. When you assign a value to the two-dimensional floating point, you must first declare a variable, then give the value to this variable, and finally assign the variable value to the two-dimensional floating point count assignment. Examples are as follows:

# clude "stdio.h" main () {float a [2] [3], x; int i, j; for (i = 0; i <2; i ) for (j = 0; j <3; J ) ) {Scanf ("% f", & x); A [i] [j] = x;}} cannot be written:

# @ include "stdio.h" main () {float a [2] [3]; INT I, J; for (i = 0; i <2; i ) for (j = 0; j <3; j ) scanf ("% f", & a [i] [j]);

In the same way, it must be entered in this format in this format in the structural floating point array variable. Examples are as follows:

# includent {float b [3]; int x;} a [2]; main () {float x; int I, j; for (i = 0; i <2; i ) for (j = 0; j <3; j ) {scanf ("% f", & x); a [i] .b [j] = x;}}

2. Pay attention to the characters after "%" in the output format

The output of the C language is complicated and is not complicated because it is very simple. It can not be said that it is not complicated, I remember that I have led to the professor of the C language in a grade test: "If the C language is difficult to test, don't take the pointer, as long as the speculation output format, I think 100% The ninety-nine students can't get it. "We didn't agree at the time. From this case, you can see the complexity of the output format of the C language. So everyone must learn to identify the characters after "%" in the output format, each character has its meaning, and there is also its role.

two. priority

Say priority, there are many friends who are not very understanding or said very vague. For this purpose, I want to pass an example of a concept. What is a priority? For example, we will always encounter the old people over the age of 70 in the end of the bus terminal, which is the priority of the priority. The C procedure is like running in line, first takes care of those priorities high operators. If the priority is the same, then it is like two (or more than two or more) 70 years old, let them sequentially car. However, the priority of the C language is not a thousand articles. It can only be said that in most cases, some operators have their own characteristics, so I have to pay attention. For example, conditions express: Condition? Result 1: Result 2, this expression makes many friends know that its role is very similar to if ... Else ... Condition judgment statement is very similar, the priority when it is operational, is not done according to the rule of C language. Therefore, for priority programming enthusiasts must be flexible, don't die hard. three. pointer

As far as personal thinks, the pointer in the C language is the most distinctive, of course, is also the most difficult. The pointer said that it is actually a form of expression, but this variable is not numerical but the address. Just like a person can use the name to express myself, you can also use the ID card number to express yourself. The author is more than three years of programming, and during this period, I have received many online email inquiry learning pointers. It is best to touch some of the principles of computer hardware work, such as direct addressing, indirect addressing, etc., only after understanding these content, you will easily pay more attention to the pointer, after all, C language is one The door allows the language of the machine language and the middle of the senior language, and there is no hardware work knowledge is difficult to understand its true meaning. However, doing things are not absolute, if you don't have this knowledge, just know that the following author summarizes the second point plus more practice:

1. The pointer is the address variable: its value has two: one is the address, the second is content. Different expressions can take different values, which is a bit different from a home address that identifies different occasions. For example, parents represent themselves in their units, and the same home address you registered in the school represent yourself.

2. The pointer is an operation, and its algorithm is consistent with the variable.

In addition, when writing a program, unless there is no need to have, the pointer variable is generally not used. Because the pointer is more complicated, it is not good to use it. " Therefore, the author recommends that you can understand the pointer, and of course, if you are ready to take the exam, you will follow.

four. function

Although many programming languages ​​have functions, but the author thinks that the function of the C language is the most attractive. If you can completely master the function of the C language, learn C is not a problem (C is built in the C language, but it is different from the advanced programming language of the C language, which adds a lot of functions.). The method of learning the function is relatively simple, only two words "remember", that is, keep in mind the function of the function, keep in mind the use of functions, and how to input the output. Some friends think that the function in the program language does not have much place, in fact, this is not correct, the function is in nature is a general program, using it to help us save a lot of programming time, a smart programmer often before writing procedures Always find what you have written first, you can replace it with a function. The author once made a comparison string experiment, using the strcmp () function in the C language, as long as one sentence, and the 30 sentences you have written, but what is the function of knowing the function! Written here The author will report a paragraph, let's send a registry comparison program written in the C language to compare the program. Note on this program Please see the text after "/ * ... * /", the program is running (in DOS mode) as follows: Compare XX1.REG XXX2.REG XXX3.txt, pay attention to the fields and fields There are spaces. (Compare is program name)

code:

# include "stdio.h" / * Define header files or include files * /

Main (argc, argv) / * Define the main function of the parameter * /

INT Argc; / * Define Parameter Type * / Char * Argv []; / * Defines Second Parameter Type * / {file * fp1, * fp2, * fp3; / * Definition file pointer * / char A, b; / * Define character variables * / if ((fp1 = fopen (argv [1], "r")) == null) / * Open the first registry backup file, if there is no existence, jump out of the program and display "The File Don` t open! "* / {Printf (" "THE FILE DON`t open!"); exit (0);} if ((fp2 = fopen (argv [2], "r")) == null) / * Open Second registry backup file, if there is no existence, jump out of the program and display "The File Don`t open!" * / {Printf ("The File Don`t open!"); Exit (0);} IF FP3 = FOPEN (Argv [3], "W")))) == NULL) / * Create a new text file to store comparison results. * / {Printf ("THE FILE DON`t!"); Exit (0);} REWIND (FP1); / * Specify file pointer FP1 points to the first registry file header * / REWIND (FP2); / * Specify that the file pointer FP2 points to the second registry file header * / while (! Feof (fp1) ||! Feof (fp2)) / * start comparison * / {a = fgetc (fp1); / * Read A registry file content and assigning a character variable a * / b = fgetc (fp2); / * read the contents of the second registry file and assign the character variable B * / if (a! = B) FPUTC (B) , fp3); / * The character variable A is different from the b, then writes different from the new text file * / if (Feof (fp1)) FPUTC (B, FP3); / * If the first registration The table file has been read, and the second file has an unread section, then write all the remainder of the second file to the new file * / if (Feof (fp2)) FPUTC (A, FP3);} / * If the second registry file has been read, the first file has unreaded part, then write all the rest of the first file to the new file * / fclose (fp1); / * Close the first Registration file * / fclose (fp2); / * Close the second registry file * / fclose (fp3); / * Close new file * /} For high-profile C language, 寥 3 What problems cannot be said. But as long as you read this article, I want to have a lot of help for you to learn this language, and you can know how to use the shortest time to learn C language and master the essence of C language. In addition, the knowledge points involved in this article are derived by the author through practice, so if there is no problem with other professional books, it can refer to this article. Finally, I wish you all the best in C language!

转载请注明原文地址:https://www.9cbs.com/read-118047.html

New Post(0)