C language entry reference (4), C language entry reference

Source: Internet
Author: User

C language entry reference (4), C language entry reference

4. parsing hello, world

C language is a computer language for process programming. It mainly uses function calls for process control. Modular process-oriented programming. Analyze the problems to be solved, find out the steps required to solve the problem, and then use the function to implement the steps to solve the problem step by step. Then, call the function one by one from top to bottom during use. Next we will analyze the hello, world program one by one.

1. Preprocessor commands and header files

The first line of the Program # include <stdio. h>. # Include is a pre-processor instruction. The pre-processor instruction starts with "#" and "#" indicates that the C pre-processor processes this instruction before the compiler takes over the instruction. # Include: "include" refers to the meaning of inclusion. It contains the function information files to be used in the next step, helping the compiler correctly combine the programs, that is, stdio. h ). The Stdio. h header file contains standard input/output functions (C language itself does not provide input and output, but is implemented by calling functions, which also reflects the lightweight charm of C ). C language implements various functions by calling functions. However, the called function is not the actual code of the function. The actual code is included in the library file. During compilation, the linker finds the library file of the function through the function declaration in the header file, and then uses the pre-processor command to link the actual code of the function to the code segment of the program.

2. main () function

The second line of the program int main (). The main function is also called the main function. Each C program should contain one and only one main function. The execution of the program starts from the main () function. Even if main () is at the end, it also starts from the main () position, that is, the main () function is the starting point of all code, without the main () function, the program cannot be compiled and run. The int before the main () function is a standard. The C99 Standard specifies that the return type of main () must be int, but in the early ansi c standard, main () the return type of the function can also be viod. Why specify the return type of the main () function? The computer checks the return value of the main () function to determine whether the program runs successfully. The return value is 0, indicating that the program runs successfully, if other values are returned, the program encountered a problem during running.

3. function bodies and statements

The part enclosed in curly braces ({}) Is the function body. A function contains several statements. There are six statements in C language.

In the hello and world routines, there are two types of statements: printf () and return. Printf () is a type of expression statement (also called "function call statement"), and return is a type of Jump statement.

4. program readability

As mentioned above, the Code is written to people. High quality code readability is high. High readability not only facilitates the understanding of other programmers, but also facilitates future maintenance and modification. The skills to improve readability include writing comments, using meaningful names for functions and variable names, separating code segments with blank lines, and each statement occupies one line. Write comments. Use/**/to create comments. The part enclosed by the/* symbol and the */symbol is the annotation. (The compiler will omit the content between the/* symbol and the */Symbol without compilation)

In C language, annotations can be written anywhere, either on a single line or on multiple lines. In addition to/**/, there are also notes for this style, this style creates comments with // symbols, but the comments in this style are limited to single lines and only the compiler that supports C99 and above supports this feature.

Code segments are separated by blank lines to differentiate the implementation and structure of code functions and facilitate understanding and maintenance.

Each statement occupies one line to make the code more clean and standardized. The C language is free to write, and multiple statements can be written in the same line, but such code is messy and difficult to understand and view.

If any error occurs in the text, please correct it. It cannot be reproduced without the support of the blogger (not to be continued ......)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.