1 Basic knowledge of C language

The development process of C language

       C language came out in the early 70s. In 1978, the American Telephone and Telegraph Company (AT&T) Bell Labs officially published the C language. At the same time, BWKernighan and DMRithchit co-authored the famous "THE C PROGRAMMING LANGUAGE" book. Usually referred to as <<K&R>> for short, some people also call it the <<K&R>> standard. However, a complete standard C language was not defined in <<K&R>>. Later, the American National Standards Institute formulated a C language standard on this basis and published it in 1983. Usually called ANSI C.

Contemporary best programming language

       The early C language was used in UNIX systems. As the powerful functions and various advantages of the C language gradually became known to people, in the 1980s, C began to enter other operating systems, and was soon widely used on various large, medium, small and microcomputers. Become one of the most outstanding programming languages ​​in contemporary times.

Features of C language

       C language is a structured language. It has clear levels, easy to organize programs in a modular manner, and easy to debug and maintain. The performance and processing ability of C language is extremely strong. It not only has a wealth of operators and data types, but also facilitates the realization of various complex data structures. It can also directly access the physical address of the memory and perform bit-level operations. Because the C language realizes the programming operation of the hardware, the functions of the C language high-level language and low-level language are integrated. It can be used for both system software development and application software development. In addition, C language also has the characteristics of high efficiency and strong portability. Therefore, it is widely transplanted to various types of computers, thus forming a variety of versions of C language.

C language version

      The most popular C languages ​​are as follows:

1. Microsoft C or MS C

2. Borland Turbo or Turbo C 

3、AT&T C   

These C language versions not only implement the ANSI C standard, but also make some supplements on this basis to make it more convenient and perfect.

Object-oriented programming language

       On the basis of C, C++ was introduced by Bjarne Strou-strup of Bell Labs in 1983. C++ has further and improved the C language and has become an object-oriented programming language. The latest versions of C++ currently popular are Borland C++4.5, Symantec C++6.1, and Microsoft VisualC++ 2.0. C++ proposes some more in-depth concepts. The object-oriented concepts it supports can easily map the problem space directly to the program space, providing programmers with a different way of thinking and programming methods from traditional structured programming. Therefore, the complexity of the entire language is increased, and it is difficult to master it.

C and C++

       However, C is the foundation of C++, and C++ and C are compatible in many aspects. Therefore, if you have mastered the C language and further study C++, you can learn object-oriented language with a familiar syntax, so as to achieve the goal of getting twice the result with half the effort.

Structural characteristics of C source program

       In order to illustrate the characteristics of the C language source program structure, first look at the following programs. These programs range from simple to difficult, showing the characteristics of the structure of C language source programs. Although the relevant content has not been introduced, you can learn from these examples the basic parts and writing format that make up a C source program.

#include "stdio.h"
#include "math.h"
int main()
{
    double x,s;
    printf("input number:\n");
    scanf("%lf",&x);
    s=sin(x);
    printf("sine of %lf is %lf\n", x, s);
}

Include is called a file containing command. The file whose extension is .h is also called a header file or header file. It contains stdio.h because both printf and scanf are in this library, and math.h is included because the sin mathematical function is used; Define two real number variables to be used by the following program; display the prompt message "input number:"; obtain a real number x from the keyboard; find the sine of x and assign it to the variable s; display the result of the program operation; the main function ends.

Structure characteristics of C source program

1. A C language can consist of one or more source files.

2. Each source file can be composed of one or more functions.

3. No matter how many files a source program consists of, there is one and only one main function, that is, the main function.

4. There can be preprocessing commands in the source program (the include command is only one of them), and the preprocessing commands should usually be placed at the top of the source file or source program.

5. Every description and every sentence must end with a semicolon. But preprocessing commands, function headers and curly braces "{}" cannot be followed by semicolons.

6. Identifier, at least one space must be added between keywords to show the gap. If there is an obvious space character, you can also add spaces to separate it.

Rules to follow when writing programs

     From the perspective of clear writing, easy reading, understanding, and maintenance, the following rules should be followed when writing programs:

1. One description or one sentence occupies one line.

2. The part enclosed in {} usually represents a certain hierarchical structure of the program. {} is generally aligned with the first letter of the structure statement, and on its own line.

3. Sentences or explanations one level lower can be written indented several spaces than sentences or explanations one level higher. In order to look clearer and increase the readability of the program. Strive to follow these rules when programming to develop a good programming style.

C language character set

       Characters are the most basic element of a language. The C language character set consists of letters, numbers, spaces, punctuation and special characters. Chinese characters or other representable graphic symbols can also be used in character constants, string constants and comments.

C language vocabulary

         The vocabulary used in the C language is divided into six categories: identifiers, keywords, operators, separators, constants, comment symbols, etc.

1. Identifier

The variable names, function names, labels, etc. used in the program are collectively called identifiers. Except the function name of the library function is defined by the system, the rest are defined by the user. C stipulates that an identifier can only be a string composed of letters (A~Z, a~z), numbers (0~9), and underscores (), and the first character must be a letter or underscore.

The following identifiers are legal: a, x, _3x, BOOK_1, sum5

The following identifiers are illegal: 3s (start with a number), s*T (with an illegal character *), -3x (with a minus sign), bowy-1 (with an illegal character minus sign)

You must also pay attention to the following points when using identifiers:

1) Standard C does not limit the length of the identifier, but it is restricted by various versions of the C language compilation system, and it is also restricted by the specific machine. For example, the first eight digits of the identifier specified in a certain version C are valid. When the first eight digits of two identifiers are the same, they are considered to be the same identifier.

2) In the identifier, case is different. For example, BOOK and book are two different identifiers.

3) Although the identifier can be freely defined by the programmer, the identifier is a symbol used to identify a certain quantity. Therefore, the naming should have corresponding meaning as much as possible to facilitate reading and comprehension, and be "as the name implies".

2. Keywords

A keyword is a character string with a specific meaning specified by the C language, and is usually also called a reserved word. User-defined identifiers should not be the same as keywords. C language keywords are divided into the following categories:

1) Type specifier

Used to define and explain the type of variables, functions, or other data structures. Such as the int, double, etc. used in the previous examples.

2) Statement delimiter

Used to express the function of a sentence. The if else used in Example 1.3 is the statement delimiter of the conditional statement.

3) Preprocessing command word

Used to represent a preprocessing command. As used in the previous examples include.

3. Operator

The C language contains a wealth of operators. Operators, variables, and functions form expressions to represent various calculation functions. Operators consist of one or more characters.

4. Separator

The separator used in C language consists of comma and space. The comma is mainly used in type descriptions and function parameter tables to separate variables. Spaces are mostly used between words in a sentence, as an interval service. There must be more than one space character between keywords and identifiers, otherwise there will be a syntax error, such as int a; written as inta; C compiler will treat inta as an identifier, and the result is bound to Something went wrong.

5. Constant

Constants used in C language can be divided into numeric constants, character constants, string constants, symbolic constants, escape characters, etc.

6. Comment

There are two kinds of comment characters in C language: "//" and "/* ... */ ".

//This is a comment, I can only comment the current line after the symbol

/*This is a comment

I can

Comment out many lines. */

In the debugging program, you can also use comment symbols to comment out the statements that are not used temporarily, so that the compilation is skipped, and the comment characters are removed after the debugging is completed.

 

 

Exchange group number: 657996991

Excerpted from the C language tutorial

Guess you like

Origin blog.csdn.net/w_hizyf_m/article/details/108730840