[转] About C language

xiaoxiao2021-03-06  18

C language (Wikipedia, the free encyclopedia)

C is a common programming language that is mainly used for system programming. It has the characteristics of efficient, flexible, rich, strong expressive and good transplantation, and is favored in programmers.

The C language is developed and improved by UNIX's developers of Dennis Ritchie and Ken Thompson developed and improved on the basis of B language developed in 1970. The C language can be widely used in different operating systems, such as UNIX, MS-DOS, Microsoft Windows, and Linux. The C language is a process-oriented language and has the advantages of advanced language and assembly language. Based on the C language, there is a C language that supports a variety of programming style. Java, JavaScript, Microsoft C #, etc. widely used on the network.

In 1983, the US National Standards Committee (ANSI) was standardized in 1983, which issued the first C language standard draft in 1983, and later issued another C language standard draft in 1987 (87 ANSI C). The latest C language standard was promulgated in 1999 and c99 adopted by ANSI in March 2000, but due to the support of the mainstream compiler manufacturer, it was not widely used until 2004, the C99 was not widely used, and several new features were added after C99. It has gradually made C language and C .

table of Contents

1 C language features

2 C language main features

3 C language history

4 C language version

4.1 K & R C4.2 ANSI C and ISO C4.3 C99

5 C language Hello World program

6 further understand C

6.1 Composite Schemrate 6.2 Conditional Statement 6.3 Cycle Schedule 6.5 Jump Statement 6.5 Operating Symbols in C99

7 data type

7.1 Basic Data Type 7.2 Arrse 7.3 Pointer 7.4 String 7.5 File Input / Output

7.5.1 Standard Input / Output

7.6 Transfer command line parameters

8 C language standard library

9 C language keyword

The Characteristic C language of the C language is the system program language. The C language retains the characteristics of the low-level language, such as pointers involving memory. The pre-processing mechanism is used such that the program can be processed by including, for example, macros. The shortcomings of C language can be improved by the updated programming language of C language. The Cyclone language has a feature that is flexible for memory errors. C and Objective C provide a programming structure for object-oriented. Java and C # add object-oriented structures to automate memory management.

The main characteristic of the C language C language retains the characteristics of low-order languages, such as indicators involving memory. The C language passes the value in the function through the parameter. The pre-processing mechanism is used such that the root source can be processed by including, for example, macros. The C language provides a set of standard libraries that provide a very useful feature. But not all these features are valid. For example, pretreatment is usually processed as a separate program, which makes the procedure with the process not necessarily completely compiled.

Although C is a high-order language, it has some characteristics of a combination language, which is the characteristics close to the low-order language for other languages. For example, in the C language, the programmer can manage computer memory. By default, the C language does not check the range of the array, that is, even if the array is off, the C language does not make an error prompt. The management of computer memory allows the programmer to get faster, more efficient programs, which is especially important for device drivers. But this also makes the program easily produce an annoying "bug", such as buffer overflow errors. However, these errors can be avoided by some tools.

The deficiencies of C language can be improved by the updated programming language developed by the C language. The Cyclone language has a feature that is flexible for memory errors. C and Objective C provide programming structures for object-oriented structures. Java and C # increase the structure of the object to automate the management of memory. C language history

The first development of C language is between 1969 and 1973. C is called C is because many of the C language is developed by an earlier programming language called B language.

In 1973, the C language can be used to write the kernel of the UNIX operating system. This is the first time to write the kernel of the operating system with a C language. Dennis Ridge and Brian Kernighan published "C Programming Language" in 1978 (The C Programming Language, often referred to as "White Paper" or "K & R").

After 1980, Bell Lab has made C grew more widely, making C once become the first choice for operating systems and applications. Even today, it is still widely used to write the operating system and the preferred language as the most widely computerized education.

In the late 1980s, the Bayi Straast Lupu and Bell Lab have added object-oriented properties for C language. This language has become C . C is now widely used in the manufacture of commercial applications under Microsoft Windows, however C is still a popular programming language for UNIX.

C language version

K & R CC is constantly improving from its first release. In 1978, Kernighan and Ridge "C-program Design Language" were published. It introduces the characteristics of the C language version below:

Struct Data Type Long INT Data Type Unsigned INT Data Type The operator = is changed to =, and it is pushed. Because = makes the compiler confused. In the next few years, "C programming language" has been extensive as a C language in fact specification. In this book, C language is usually expressed as "K & R C". (Second Edition includes ANSI C standard)

K & R C is usually used as the most basic C language part supported by the C compiler. Although the current compiler does not necessarily follow the ANSI standards, K & R C is still subject to programmaking as the bottom request of C language. But in any case, it is now far from K & R C, because these compilers use ANSI C standards.

ANSI C and ISO C 1989, C language was standardized by ANSI. ANSI X3.159-1989. One purpose of standardization is to expand K & R C. This standard includes some new features. After the K & R is published, some new features are "unfair" to the C language.

The Void function function returns a struct or UNION type VOID * Data type In ANSI standardization, some new features are added. ANSI also has a standard library. The ANSI C standard was adopted by ISO (International Standardization) to become ISO 9899. The first version of ISO is published in 1990.

C99 After ANSI standardization, C language standard remains unchanged in a quite time, although C continues to improve. (In fact, Normative Amendment1 has developed a new C language version in 1995. But this version is rarely known.) The standard has experienced improvements in the 1990s, which is ISO9899: 1999 (published in 1999). This version is a commonly mentioned C99. It was adopted by ANSI in March 2000.

The features included in C99 are:

The compiler is limited, such as the source program requires at least 4095 bytes, and the demand of the variable name function name supports 63 bytes (Extern requires support to 31) pre-processing enhancement. For example: macro supports the parameter #define macro (...) __va_args__ When using the macro, if the parameter is not written, the macro uses #, ## will expand into an empty string. (Previously wrong) Support // Row Note (This feature is actually supported on a lot of compilers in C89) Added new keywords restrict, inline, _complex, _imaginary, _bool support long long, long double _complex, FLOAT _COMPLEX supports <::> <%%>%:%:%:, wait for strange symbol replacement, D & E mentioned this array that supported unregistered. The length of the array can be used. When the declaration type is used, it is written like INT A [*]. However, considering efficiency and implementation, this is not a new type. So you can't use it in the global, or Struct Union, if you use something like this, the goto statement is limited. Variable declaration does not have to be placed at the beginning of the statement block, the FOR statement advocates such a writing for (int i = 0; i <100; i) means that INT i's statement is placed inside, i is only valid inside for for. When a similar structure requires temporary construction, you can use (Type_name) {xx, xx, xx}, which can be written like a C constructor, now you can write: struct {Int a [3], B; } hehe [] = {[0] .a = {1}, [1] .a = 2}; struct {Int A, B, C, D;} hehe = {.a = 1, .c = 3, 4, .b = 5} // 3, 4 is the string of .c, .d assignment, / u Support Unicode's character support 16-based floating point number, so PrintF scanf formatted string more supported LL / LL (I64 in VC6) corresponds to a new LONG long type. The internal data description of the floating point number supports new standards. This can be specified in the #pragma compiler, in addition to existing __line___file__, supporting a __func__ can get the current function name for a very number of expressions, also allowed compilation During the decline in the definition of /% of the processing negatives, such as the old standard - 22/7 = -3, -22% 7 = -1, now -22 / 7 = -4, -22% 7 = 6 Cancellation of the non-write function Return Type The default is the INT specification allows the last array write to the struct definition [] does not specify its length description const const amount I; it will be treated as const Int i; add and modify some standard heads Files, such as define some standard length INTTYPES.H> definition of defined wide character a bit generic taste. H> related to floating point. has a VA_COPY to copy the parameters.

Many Struct TMX doing the StructTM extended input and output to wide characters and long intenses, etc., the interests of each company have different interests of C99 support. When GCC and other commercial compilers support most of the characteristics of C99, Microsoft and Borland seem to be not interested in this. C Language Hello World Program The following is a simple program that outputs Hello World on the standard output device, which is usually the first program when you start learning programming languages:

#include

INT main (void) {Printf ("Hello, World! / N"); return 0;}

Further understand the CC language consisting of functions and variables. The function of C is like subroutines and functions in Fortran.

In the C language, the program starts from MAIN. The main function works by calling and controlling other functions. For example, the above printf. Programmers can write a function yourself or call the function from the library. On the above RETURN 0; allows main to return a value to the case of the caller, indicating that the program has been successfully run.

A C language function consists of return value, a function name, a parameter list (or Void indicates no return value) and a function body. The syntax of the function body is the same as the other composite statement part.

The format of the composite statement in the composite statement C language is:

{Statement; statement; ...} Composite statement allows several statements to become a statement.

The conditional statement C language has three conditional statements. Both are IF, the other is Switch.

Two IF includes:

IF (Conditional Expression) statement;

IF (conditional expression) statement; ELSE statement; in the conditional expression, any non-zero value represents the condition true; if the condition is not satisfied, the program will skip the statements behind the IF, directly execute the following statement. However, if the IF has an else, the program jumps to the ELSE when the condition is not true.

Switch is often used to control several conditions with clear values. It requires that the condition values ​​are usually integer or characters. Condition transfer with Switch is Case. Using the standard values ​​behind the case, the control program will be executed down to the CASE that satisfies the condition until the statement ends or encounters Break. You can usually use default to put other exceptions. If the conditions in the Switch statement are not true, the control program will jump to the Default execution. Switch is a nested.

Switch () {case : case : default: }

There are three forms of loop statements in the circular statement C language:

DO While (); while () ; for (; ; ) in While and In DO, the statement will be executed to the value of the expression is zero. In the DO ... While statement, the cyclic body will be executed at least once. These three cyclic structures can be transformed with each other:

For (E1; E2; E3) S;

E1; While (E2) {s; E3;} When the cycle condition has been true, a dead cycle will be generated.

Jump statement jump statements include four: goto, continue, break, and return.

The GOTO statement is unconditional transfer statement:

Goto tag

The tag must be defined in the current function, using the "Tag:" format. The program will be jumped to the marker. Since Goto is prone to reading difficulties, you should use it less. The Continue statement is used in a loop statement, and the role is to end the current round of loop, and immediately start the next round of loop.

The BREAK statement is used in a cycle statement or Switch, and the role is to end the current loop and jump to the cyclic body to continue. But using Break can only jump out of a layer of loop. When you want to jump out multiple cycles, you can use GOTO to make the program more concise.

When a function is executed, use returna when returning a value. Return can follow an expression or variable. If there is no value after return, the non-return value will be executed.

In the C99, the symbol () [] ->.! - (cast) parentheses, members, logic are non-, self-add, self-reduced, forced conversion - * & ~! - SIZEOF single operator * /% Arithmetic operator - Arithmetic Operator << >> Binding Operator <<=>> = Relational Operator ==! = Relational Operation Symbol & Bit and ^ Digital or | Bit or & & Logic or? : Conditional operator = = - = * = / =% = << = >> = & = | = ^ = assignment operator, sequential operator

Data Type [Edit] Basic Data Type Note: The following is a typical data bit length and range. But the compiler may use different data bit lengths and ranges. This depends on the compiler used. Please refer to the specific reference manual.

The length of the underlying data is illustrated in the header file and . The range of float, double, and long double is typical data mentioned in IEEE 754.

Keyword long range char 1 -128..127 or 0..255 unsigned char 1 0..255 sign char 1 -128..127 INT 2 or 4 -32768..32767 OR-2147483648..2147483647 Short Int 2 -32768..32767 Long Int 4 -2147483648..2147483647 FLOAT 4 ??? Double 8 ??? long double 8 ???

An array If a variable name follows a number of brackets with numbers, this statement is an array declaration. Strings are also an array. They are the end of the array as the NUL of ASCII.

E.g:

INT MyVector [100]; char mystring [80]; float mymatrix [3] [2] = {2.0, 10.0, 20.0, 123.0, 1.0, 1.0} char lexicon [10000] [300]; / * Total 1,000 largest A character array of length 300. * / int A [3] [4]; The last example above created an array, but it can also be regarded as a multi-dimensional array. Note that the subscript of the array starts from 0. The structure of this array is as follows:

A [0] [0] a [0] [1] a [0] [2] a [0] [3] a [1] [0] a [1] [1] a [1] [2] a [1] [3] a [2] [0] a [2] [1] a [2] [2] a [2] [3]

Pointer If a variable declares, use the * number in front, indicating that this variable is a pointer.

E.g:

INT * PI; / * Pointer * / int * API [3]; / * is 3 * / char ** argv; / * points to a character pointer by pointing to a pointer to integer data; The pointer * / The value indicated by the address in the pointer can be read in the program. For example, in the first example, * Pi is a integer data. This is called a reference to a pointer. Another operator &, called taking address operator, which will return a variable, array, or store address. Therefore, the following example:

INT I, * PI; / * int AND Pointer to int * / pi = & i; i and * Pi can be used inter alternate each other in the program until PI is changed to a pointer to another variable.

Strings To use strings and do not need a reference library, the C Standard Library does include functions for operation of strings so that they look like a string rather than arrays. Use these functions require reference header file .

STRCAT (DEST, SOURCE) - Connect two strings and add SOURCE to DEST. Strchr (s, c) - Find the position of the first appearance of the character S in the string C. Returns NULL when not found. STRCMP (A, B) - Compares the size of strings A and B. If the two strings are the same, return 0; if A> B is returned; if a B is returned; if a

File Input / Output In C language, input and output are implemented by a set of functions in the standard library. In ANSI / ISO C, these functions are defined in the header file .

Standard input / output has three standard input / outputs are predefined:

STDIN Standard Input Stdout Standard Output STDERR Input Output Error These definitions are automatically opened and closed during operation, so they do not need to perform explicit definitions.

The following example shows how a filter program is constituted.

INCLUDE int main () {Int C; while ((c = getchar ())! = EOF) {/ * {FPUTS ("An Error Eee Occurred) / N ", stderr); Break;} / * ... * / putchar (c); / * ... * /}}

Passing command line parameters The parameters of the command line give the program will be implemented by defining a integer parameter (int) (int) and a pointer type parameter (char **) that points to the character pointer in the main () function. Number, the latter passes the command line parameter content. The two parameters are named Argc and Argv, respectively. The program file name is used as the first command line parameter.

For the following programs:

INCLUDE int main (int Argc, char ** argv) {INT i; for (i = 0; I

The following output results are obtained: 0: C: /TC/a.exe 1: One 2: Two 3: Three

C language standard library The following list lists the standard libraries provided by the C language, and the library is referenced by #include.

In the C89 standard:

in the 95-year-old revision

Added six functions in C99

CHAR SHORT INT UNSIGNED Long Float Double Struct Union Void Enum Signed Const Volatile Typedef Auto Register Static Extern Break Case Contin Refault Do else for goto if return switch while sizeof

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

New Post(0)