One of the ways to learn C language --------- C language basics

Source: Internet
Author: User

C language basics

I. Basic syntax structure of C language program:
1. main ()
The common structure of the main () function is as follows.
Voidmain ()
{
... /* Function body */
}
2. If you need to accept the command line parameter during program execution, the format of the main () function is as follows.
Voidmain (intargc, char * argv [])
{
...
}
Ii. single-row statements and compound statements

1. Single Row statements
In C language programs, a single-line statement is followed by a semicolon (;), which is the end symbol of a C language program. All C language statements must end with a semicolon.
Note that the single-line statement in C does not mean that the statement occupies only one row, but is a statement ended with a semicolon.
For example, printf ("This is c"); // This is an output statement and ends.

2. Compound statements
In a program, you sometimes need to execute several adjacent statements as a whole, and you can enclose these statements in curly brackets to form a composite statement, also known as a statement block.
For example: for (int a = 0; a <9; a ++ ){
...................
}
3. Notes
The C-language annotator is a string starting with "/*" and ending. Comments between "/*" and. During program compilation, comments are ignored, and no comments are processed.
Annotations can appear anywhere in the program to notify users or explain the meaning of the program.

Iii. Structural Features of C language programs

A c language source program can be composed of one or more program source files. Each source file can contain one or more functions.
No matter how many files a source program is composed of, there is one and only one main function, that is, the main function.

The source program may have preprocessing commands (the include command is only one of them). The Preprocessing commands should usually be placed at the beginning of the source file or source program.
Each description must end with a semicolon. However, the pre-processing command, the function header and the curly braces "}" cannot be followed by extra points.
At least one space must be added between identifiers and keywords to indicate the interval. If there is an obvious delimiter, there is no space to separate it.


Iv. Identifiers and keywords
1. identifier
In C language programs, the identifier ranges from 1 ~ It can contain 8 characters. The characters that constitute the identifier can only be underscores (_) and numbers (0 ~ 9) and English letters, and the first character of the identifier can only be an underscore or an English letter.

C language is a language that is case sensitive to letters. When defining identifiers, you must note the case sensitivity of letters.
Note the following when using identifiers.


① Standard C language does not limit the length of identifiers, but it is limited by the C language compilation systems of various versions and by specific machines. For example, in a certain version of C language, the first eight bits of the identifier are valid. When the first eight bits of the two identifiers are in the same phase, they are considered to be the same identifier.
② In identifiers, the Case sensitivity is different. For example, BOOK and book are two different identifiers.

③ Although the identifier can be defined by the programmer at will, it is a symbol used to identify a certain amount. Therefore, the name should be meaningful as much as possible for reading and understanding ".

2. Keywords

In C language programs, there is also a special type of identifiers, which are only for the system and cannot be used as user-defined identifiers. This is the keyword. Keywords are system reserved identifiers with special meanings. Therefore, they are also called system reserved words.
Keywords are strings with specific meanings specified by C language. User-Defined identifiers should not be the same as keywords. The keywords of C language are divided into the following types.


(1) type specifier.
The type used to define and describe variables, functions, or other data structures. For example, int and double used in the previous example.

(2) statement Definition character.
Indicates the function of a statement. For example, ifelse used in example 1.3 is the statement Definition character of the Condition Statement.

(3) pre-processing command words.
Used to represent a preprocessing command. For example, include is used in the previous examples.


From 10-3G-He Jinchao

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.