I. Program Structure
1.C Program Structure: Any C program is composed of one or a small program code block, each small program has its own function, generally referred to as the function of these small programs. So, it can also be said that C programs are composed of functions.
Two. Concept of function:
1. Function Name: A program is composed of countless functions, each of which has its own name, that is, names.
2. Call functions: Call functions according to function names, perform functions by calling functions, each function has its own function.
Three. Entrance to the program: Each program has a main () function, which is the entry for the entire program, regardless of the number of functions of the entire program, is executed from main ().
Four. Writing functions
1. Write the main function, which is the function body in curly braces.
int main () { return 0;}
2. Write multiple functions and make calls
1 intTest ()2 {3printf"hello\n");4 return 0;5 }6 intMain ()7 {8 test ();9 Return0;Ten One}
3. Use the printf () function to print content to the screen
1 #include <stdio.h>2int main ()3{4 printf ("hello,world"); 5 return 0 ; 6 7 }
Five. Compiling
1. Operating in the terminal
(1) Enter the Cc-c file name in the terminal. C
(2) compile successfully, generate. O Target file
2. Compiler error and alarm function
(1) If there is a problem with the syntax of the code, the compiler will report a direct error, and will indicate the exact number of errors and the corresponding line numbers.
(2) If there is a bug in the program, it cannot be compiled successfully or produced. o target file.
(3) Warning messages are just some of the compiler's recommendations and do not affect the program's compilation through
Six. Links
1. The role of the link: the. o target file is combined with the C-language function library to generate the executable file.
2. In terminal input: CC file name. o The successful link will automatically generate the a.out executable.
Seven. Operation (two modes of operation)
1. Double-click the a.out file to run
2. In terminal input:./a.out Run File
Eight. Other directives:
Modify executable file name: Enter cc original file name in terminal. o-o file name
Compile and link execution: CC file name. C
Nine. Common errors in the encoding process
Do not write a semicolon, or write a Chinese semicolon
String with either a double quote or a single quote,
The file extension is not. C alive. C
Compile the file with absolute path, note the location where the target file is generated
10. Extension of Common Files
(1). c file is a C language source file, generated when writing a C language program
(2). o file is the target file, successfully generated in C language Program compilation
(3) an. Out file is an executable file that is generated when the link succeeds
11. Summary of TERMINAL commands:
Compile: Cc-c file name. C
Link: cc file name. O
Compile, Link: cc file name. C
Run the executable file:./a.out
12. What errors will be encountered during the development process? How to solve?
Syntax error, can be resolved by compiler errors
Logic error, need to be patient to debug program
C-Basic concepts