C Basic Syntax
This chapter introduces the basic syntax rules of C: identifiers, keywords, data types, statements, expressions, comments, code style, etc.
1. Identifiers and Naming Conventions
- Composed of letters, numbers, underscores, cannot start with a number
- Case sensitive
- Recommended to use meaningful lowercase with underscores (snake_case)
2. Keywords
Examples: int, char, float, double, if, else, switch, for, while, do, return, break, continue, sizeof, typedef, struct, union, enum, const, static, volatile, etc.
3. Statements and Semicolons
Each statement ends with a semicolon ;, code blocks are wrapped with curly braces {}.
4. Variables and Constants
5. Expressions and Operators
6. Input and Output
Common format specifiers: %d, %u, %ld, %f, %lf, %c, %s, %p.
7. Control Structures
- Conditional: if/else, switch
- Loops: for, while, do-while
- Jumps: break, continue, return