C Language notes by kingwei
1 Overview
1.1 Development History
C language was released in early 1970s. In 1978, the at&t Bell lab officially published the C language. The famous book "The C programming language" is also co-authored by B. W. kernighan and D. M. ritchit. Generally referred to as "K & R", or "K & R" standard. However, K & R does not define a complete C language. Later, the American National Standards Institute developed a C language standard based on this, which was published in 1983. It is usually called ansi c.
C is a structured language. It has a clear hierarchy, which facilitates the organization of programs in a modular manner and facilitates debugging and maintenance. Because the C language implements hardware programming, the C language integrates the functions of the advanced and low-level languages. Therefore, some people call it an intermediate language. In addition, C language features high efficiency and portability. Therefore, it is widely transplanted to various types of computers, thus forming multiple versions of C language.
Currently, the most popular C languages are as follows:
Microsoft C, or MS C
Borland Turbo C, or Turbo C
· AT & T c
1.2 program structure example
The Code listed in this document is successfully run in Dev-C ++.
.
# Include <stdio. h>/* include header file */
# Include <stdlib. h>
# Define max_length 100/* macro definition */
Int length;/* define the global variable */
Int list [max_length];
Int comp (const void * P1, const void * P2)/* define function body */
{
Int e1 = * (int *) P1);/* defines the local variable */
Int e2 = * (int *) P2 );
If (E1> E2)/* branch structure (if-else )*/
Return 1;
Else if (E1 <E2)
Return-1;
Else
Return 0;/* return value to the main function */
}
Int main ()/* main function */
{
Int I;
Freopen ("in.txt", "r", stdin);/* sequential structure */
Freopen ("out.txt", "W", stdout );
While (scanf ("% d", & length )! = EOF)/* loop structure (while )*/
{
For (I = 0; I <length; I ++)/* loop (for) control input */
Scanf ("% d", & list [I]);
Qsort (void *) List, length, sizeof (INT), comp );
For (I = 0; I <length; I ++)/* loop (for) control output */
Printf ("% d", list [I]);
Printf ("/N ");
}
Return 0;/* The process returns a value to the system */
}
1.3 compilation and Connection
Any computer language should be converted from a form that is easy to understand (Source Code) to a form that can be executed by a computer (machine instructions ). For C language programs, the source code needs to be preprocessed first, and the Preprocessor processes the pre-compiled commands. The generated code is usually stored in an intermediate file. Then use the compiler to compile the intermediate file into the target file. Finally, through the connector (linker), connect the target module and the library, and add the startup module to become a program that can be loaded and executed by the system.
Development Environment compilation (compile) connection (Link)
(Tool) C source file ------------> target file ------------> final file
Windows *. C *. OBJ *. EXE Executable File
(VC) *. Lib static library file
*. Dll dynamic library file
Linux *. C *. O *. --- Executable File
(Kdevelop) *. A static library file
*. So dynamic library file
Therefore, it is inappropriate to call TC, Vc, and other programming software compilers. These software is an integrated development environment integrating tools such as editing, preprocessing, compilation, connection, and debugging. Taking Dev-C ++ as an example, it provides a window interface editing environment and some configuration options, but the internal compiler is still gcc/gw.w.w.w.w.w.gdb.exe as the internal compiler tool.