C program structure

C program includes the following components:

      1) preprocessing directive

       2) The main function

       3) The main body of the function

       4) Notes (caption)

The sample program:

#include<stdio.h>
int main()
{
printf("hello world\n");

return 0;
}

1. # include <stdio.h> is more than one line preprocessor directive that tells the C language compiler before compilation to include stdio.h file, the program uses the printf function, if you do not include the header file, there will be compile-time caveat.

2.int main () is the main function, the program execution starts from here, the code of the main body of the function in the curly braces. In the same program, main function can only have one.

3. The main function calls the library function printf C language for the output of a text. The end of the text \ n represents for line, a plurality of \ n can output a plurality of spaces.

4.return 0 main function returns, the program exits.

Since I was using vi under linux programming tool, enter the above source code, source code file is named book0.c.

At the command prompt, type: gcc -o book0 book0.c, compile the source code, if there is no compilation errors, will generate an executable file named book0, if not with -o to specify the output file, the default output file is a.out.

Enter at the command prompt: ./ book0, execute the file, you can see the results.

Precautions:

/ ** / multi-line comments

// a single line comment (Comments are not executed, will be skip compiler compile time)

#include preprocessing directives comprise other files.

Main starting point for program execution.

{} Function body, the start and end of a block of statements.

() Function parameters in parentheses.

"" String in double quotes.

\ N newline.

; End of a line of code.

C language strictly case-sensitive;

Chinese full-width punctuation C language does not recognize, would compile-time error;

If only; number indicates an empty statement.

 

 

Guess you like

Origin www.cnblogs.com/liao1998-python/p/11318912.html
Recommended