Lexical symbols in C language

Lexical symbols in C language

A lexical symbol is a meaningful minimum grammatical unit composed of several characters.

According to the role in the program, it can be divided into: keywords, identifiers, operators, separators and punctuation marks.

1. Keywords

​ ——The lexical symbols defined by the system have special meanings, and users are not allowed to redefine them.

(1) Storage type : auto (automatic type) static (static) extern (external) register (register)

(2) Data type : char (character type) short (short integer type) int (integer type) long (long integer type) float (floating point type) double (double precision floating point type) signed (signed) unsigned (no symbol) struct (structure) union (union) enum (enumeration) void (empty type)

(3)控制语句:if else while do for switch case default break continue goto return

(4) Others : sizeof (the size of the space occupied by the calculated data) const (read-only) typedef (rename) volatile (to prevent the compiler from being optimized)

2. Identifier

The lexical symbols defined by the programmer according to the naming rules are used to define macro definition names, variable names, function names, and custom type names, etc.

Naming rules for C language identifiers:

  • (1) The identifier consists of letters, numbers and underscores

  • (2) The first character of the identifier must be a letter or an underscore

  • (3) Cannot be the same as the keyword

3. Operator

Operators are lexical symbols that represent operations, and are divided into functions: arithmetic operations, logical operations, relational operations, assignment operations, bit operations, and other operators.

  • (1) Arithmetic operators: + - * / % ++ –

  • (2) Assignment operators: = += -= *= /= %=

  • (3) Relational operators: < <= > >= == !=

  • (4) Logical operators: && || !

  • (5) Bitwise operators: & | ~ ^ << >>

  • (6) Other operators: ternary operator sizeof()

4. Separator

Used to separate other lexical symbols, mainly including: spaces, tabs, newline symbols and comments.

Through the proper use of delimiters, the appearance format of the code is clearer and easier to read, and it can also help analyze syntax errors in the program.

5. Punctuation marks

The punctuation marks in C language include comma, semicolon, colon, curly braces, parentheses and square brackets.

The role of punctuation is similar to that of delimiters, but the usage is very strict and has clear grammatical rules. If you make a mistake, an error will be reported.

Guess you like

Origin blog.csdn.net/weixin_43624626/article/details/130659478
Recommended