C language identifiers, keywords, comments, expressions, and statements

Identifiers
When defining variables, we use names such as a, abc, and mn123. They are all created by programmers themselves, and generally can express the role of variables. This is called an identifier (Identifier).

The identifier is the name given by the programmer himself. In addition to the variable name, we will also talk about function names, macro names, structure names, etc., which are all identifiers. However, the name cannot be chosen casually, and the specification must be followed; C language stipulates that identifiers can only consist of letters (A~Z, a z), numbers (0 9) and underscores (_), and the first character must be a letter or an underscore, not a number.

The following are legal identifiers:
a, x, x3, BOOK_1, sum5

The following are illegal identifiers:
3s cannot begin with a digit
s T is an illegal character
-3x cannot begin with a minus sign (-)
bowy-1 an illegal character minus (-) is present

When using identifiers, you must also pay attention to the following points:
Although C language does not limit the length of identifiers, it is limited by different compilers and operating systems. For example, a compiler stipulates that the first 128 bits of an identifier are valid, and when the first 128 bits of two identifiers are the same, they are considered to be the same identifier.
In identifiers, capitalization makes a difference, eg BOOK and book are two different identifiers.
Although the identifier can be freely defined by the programmer, the identifier is a symbol used to identify a certain quantity. Therefore, the name should have a corresponding meaning as much as possible, so as to be easy to read and understand, and be "just as the name implies".
Keywords
Keywords (Keywords) are character strings with specific meanings stipulated by C language, usually also called reserved words, such as int, char, long, float, unsigned, etc. The identifier we define cannot be the same as the keyword, otherwise an error will occur.
You can also understand keywords as identifiers with a special meaning, they are already used by the system and we cannot use them any more.
A total of 32 keywords are specified in the standard C language. You can refer to C language keywords and their explanations [32 in total], and we will explain them one by one later.
Notes
Notes (Comments) can appear anywhere in the code, used to prompt the user or explain the meaning of the code. When the program is compiled, the comment is ignored and nothing is done, as if it did not exist.

C language supports single-line comments and multi-line comments:
single-line comments start with // until the end of the line (no newline);
multi-line comments start with / and end with /, and the comment content can have one or more lines.

An example of using comments:
/*
Powered by: c.biancheng.net
Author: Yan Changsheng
Date: 2017-10-25
/
#include <stdio.h>
int main()
{ /
puts will automatically add a newline at the end*/
puts("http://c.biancheng.net");
printf("C language Chinese website\n"); //printf needs to manually add a newline
re turn 0;
}
Operation result:
http://c.biancheng.net
C language Chinese website

In the process of debugging the program, you can temporarily comment out the unused statements, so that the compiler will skip and ignore them, and remove the comments after debugging.

It should be noted that multi-line comments cannot be nested. For example, the following comment is wrong:
/ C Language/ Chinese /网/
and the following comment is correct:
/ C Language Chinese Network / / c.biancheng.net /
Expression (Expression) and Statement (Statement)
In fact, we have mentioned the two concepts of "expression" and "statement" many times before.

The concepts of expression (Expression) and statement (Statement) are not clearly defined in C language: an expression
can be regarded as a calculation formula, which is often composed of data, variables, operators, etc., such as 3*4+5, a=c=d, etc. The result of the expression must be a value; the scope of the statement is wider, not necessarily calculation, not necessarily having a value, but can be an operation, a function, a selection structure, a loop,
etc.

Quickly draw the key point:
the expression must have an execution result, which must be a value, for example, the result of 3 4+5 is 17, the result of a=c=d=10 is 10, and the result of printf("hello") is 5 (the return value of printf is the number of successfully printed characters).
Those ending with a semicolon; are often called statements, not expressions, such as 3
4+5;, a=c=d;, etc.

Guess you like

Origin blog.csdn.net/D0126_/article/details/131450014