C语言常用语法提要(一)

  1. Identifier

Identifiers can consist of letters, numbers, and underscores. Identifiers must begin with a letter or underscore, and case letters are considered to be two different characters. Different systems have different regulations on the number of characters of identifiers, generally allowing 7 characters.

  1. Constant
    You can use:

    (1) Integer constant
    Decimal constant.
    Octal constant (a sequence of numbers starting with 0).
    Hexadecimal constant (a sequence of numbers starting with 0x).
    Long integer constant (followed by a number with the character L or L).

    (2) Character
    Constant is a character extended by a single apostrophe. Escape characters can be used.

    (3) Real constant (floating point constant)
    Decimal form.
    Eexponential form.

    (4) A sequence of characters enclosed by double apostrophes.

  2. Expression

(1) Arithmetic expression
Integer expression: the amount of operation involved in the operation is an integer, and the result is an integer.
Real type expression: the operation amount involved in the operation is real type, which is converted to double type in the operation process, and the result is double type.

(2) A logical expression is an integer connected by a logical operator, resulting in an integer (0 or 1). Logical expression can be regarded as a special form of integer expression.

(3) An integer connected by a bitwise operator, resulting in an integer.
Bit expressions can also be considered as a special form of integer expressions.

(4) A cast expression casts the type of an expression with the (type) operator, such as (float) (a).

(5) Comma expression (sequential expression)
in the form of:
expression 1, expression 2,… , expression n
in order to find expression 1, expression 2,… , the value of expression n, and the result is the value of expression n.

(6) The assignment expression assigns the value of the expression on the right side of the assignment number to the variable on the left side of the assignment number. The value of the assignment expression is the value of the variable assigned after the assignment.

(7) The form of conditional expression is: logical expression? Expression 1: expression 2.
If the value of logical expression is non-zero, the value of conditional expression is equal to the value of expression 1; if the value of logical expression is zero, the value of conditional expression is equal to the value of expression 2.

(8) pointer expression Operate on data of pointer type, for example, P-1, P1-P2, etc. (where P1, P2, P3 have been defined as pointer variables to array, P1 and P2 point to operations in the same array), and the result is pointer type.

The above expressions can contain related operators, or they can be initial equivalents without any operators (for example, constants are the simplest form of arithmetic expressions).*

发布了131 篇原创文章 · 获赞 94 · 访问量 2941

猜你喜欢

转载自blog.csdn.net/qq_45645641/article/details/105149426