Entering the School of Information Engineering, accompanied by “Internet +”, we embark on a new era of information development!

Understanding the Structure of C Language Programs
We will introduce the basic components, format, and good writing style of C language using a simple C program example to deepen everyone’s understanding of C language.
Example 1: A C program to calculate the sum of two integers:
#include
int main() {
int a, b, sum; /* Define variables a, b, and sum as integer variables */
a = 20; /* Assign the integer 20 to integer variable a */
b = 15; /* Assign the integer 15 to integer variable b */
sum = a + b; /* Assign the sum of the two numbers to integer variable sum */
printf(“a=%d,b=%d,sum=%d\n”, a, b, sum); /* Output the calculation result to the display */
}
#include
int main() {
int a, b, sum; /* Define variables a, b, and sum as integer variables */
a = 20; /* Assign the integer 20 to integer variable a */
b = 15; /* Assign the integer 15 to integer variable b */
sum = a + b; /* Assign the sum of the two numbers to integer variable sum */
printf(“a=%d,b=%d,sum=%d\n”, a, b, sum); /* Output the calculation result to the display */
}
Important Notes:
1. Any C language program must include the following format:
int main() { }
This is the basic structure of a C program, and every program must contain this structure. The content inside the parentheses can be left empty, in which case the program will not execute any results.
2. main() – known as the “main function” in C language, a C program has only one main function, and any C program always starts executing from the main function; the pair of parentheses following the main function cannot be omitted.
3. The content enclosed in curly braces { } is called the function body of the main function, and this part contains the content that the computer will execute.
4. Every statement inside { } ends with a semicolon (;). In C language, we refer to a statement that ends with a semicolon as a C language statement, and the semicolon is the symbol that indicates the end of a statement.
5. printf(“a=%d,b=%d,sum=%d\n”, a, b, sum); – By executing this C language system-provided screen output function, users can see the running results. After running this program, the following result will be displayed on the monitor:
a=20,b=15,sum=35
6. #include
Note: (1) This line starts with # (2) This line does not end with a semicolon; hence it is not a statement. In C language, it is referred to as a command line or “preprocessor directive”.
7. The part of the program that starts with /* and ends with */ is the comment section of the program. Comments can be added anywhere in the program to improve readability but are completely ignored by the computer when executing the content of the main function; in other words, the computer treats the comment section as if it does not exist in the main function.

The Process of Generating C Programs
A C program is first compiled from the source file to generate an object file, which is then linked to generate an executable file.
The source program has the extension .c, the object program has the extension .obj, and the executable program has the extension .exe.
Identifiers
When writing a program, names must be assigned to functions, variables, etc. This name is called an identifier. The naming rules for identifiers in C language are as follows:
-
Identifiers can only consist of letters, digits, and underscores;
-
The first letter of an identifier must be a letter or an underscore;
-
Identifiers are case-sensitive, such as If and if are two completely different identifiers.
Valid identifiers are: A6, b_3, _mn Invalid identifiers are: ab#12, 8m, tr3:4, yes no
Identifiers cannot be the same as keywords that have special meanings in the program, cannot be the same as user-defined function names, and C language library functions. In the program, various identifiers should not be repeated to facilitate distinction. When choosing variable names and other identifiers, one should aim for “self-explanatory names”.

Identifiers can be classified into the following three categories:
1. Keywords
Keywords are a class of identifiers with specific meanings, specifically used to describe specific components of C language, and cannot be used as user identifiers.
auto break case char union do double else enum extern goto if int long short signed static sizeof struct switch unsigned void for while typedef continue float return typedef default
auto break case char union do double else enum extern goto if int long short signed static sizeof struct switch unsigned void for while typedef continue float return typedef default
2. Predefined Identifiers
Predefined identifiers also have specific meanings in C language but can be used as user identifiers. Predefined identifiers are divided into two categories:
(1) Library function names, such as (printf, scanf, sin, isdigit, etc.) (2) Compiler directive names, such as (define, include)
3. User Identifiers
User-defined identifiers are identifiers defined by users as needed. Regardless of how identifiers are defined, they must conform to the three naming rules for identifiers.

Constants
During program execution, a quantity whose value cannot be changed is called a constant. There are five types of constants: integer constants, real constants, character constants, string constants, and symbolic constants.
(1) Number Conversion
There are four forms of representation for numbers:
①: Binary: All numbers consist of 0 and 1, with every two making one; binary numbers do not have the digit 2. Example: 110101 ②: Octal: Starts with the digit 0 (note it is not the letter O, o), all digits consist of 0 to 7, with every eight making one; octal numbers do not have the digit 8. Example: 0112, 0123, 077 etc. ③: Decimal: All digits consist of 0 to 9, with every ten making one; decimal numbers do not have the digit 10. Example: 0, 12, -15 etc. ④: Hexadecimal: Starts with 0x or 0X (digit 0 plus letter x), all digits consist of 0 to 9, A to F (or a to f), with every sixteen making one (where A, B, C, D, E, F represent 10, 11, 12, 13, 14, 15 respectively). Example: 0x4A, 0X14c7 etc.
Internally, computers represent and store numbers in binary form. Ordinary decimal numbers input by users must be converted to binary for internal storage, and similarly, the results of computations are also binary, which generally need to be converted back to decimal for user readability. This conversion is usually performed automatically by the computer.
(1) Converting Decimal to Binary, Octal, and Hexadecimal
Division: Divide the decimal number by 2, record the remainder, and continue dividing the quotient by 2 until the quotient is 0. The sequence of remainders obtained is the binary equivalent of the decimal number. The conversion methods for octal and hexadecimal are the same.
Example: The binary equivalent of the decimal number 13 is 1101, the octal equivalent is 015, and the hexadecimal equivalent is D.
(2) Converting Binary, Octal, and Hexadecimal to Decimal
Multiplication and Summation: Each bit of the binary number from low to high (where the right is low and the left is high) is multiplied by 2^0, 2^1, 2^2, etc., and the products are summed.
For example: (1101)₂ = (13)₁₀ (317)₈ = (207)₁₀ (23E)₁₆ = (574)₁₀
(3) Converting Binary to Octal and Hexadecimal
①: Binary to Octal: Convert every three bits from right to left into decimal, and combine the results to get the corresponding octal number (note: pad with zeros if the high bit is less than three). Example: (010 110 111)₂ = (267)₈ ②: Binary to Hexadecimal: Convert every four bits from right to left into decimal, and combine the results to get the corresponding hexadecimal number (note: pad with zeros if the high bit is less than four). Example: (0101 1011)₂ = (5B)₁₆ ③: Octal to Binary: Convert each digit into three binary digits Example: (13)₈ = (001 011)₂ = (1011)₂ (note: drop leading zeros, as 0 has no significance in the high bit) ④: Hexadecimal to Binary: Convert each digit into four binary digits Example: (E3)₁₆ = (1110 0011)₂

(2) Integer Constants
Integer constants come in three forms: decimal integer constants, octal integer constants, and hexadecimal integer constants.
(Note: there are no direct representations of binary integer constants in C language, and binary will not appear in C language source code.)
The writing format is as follows:
Decimal integer constants: 123, 0, -24, 85L (long integer constant), etc. Octal integer constants: 051, -026, 0773, etc. Hexadecimal integer constants: 0x55, 0x1101, 0x, 0x5AC0, -0xFF. Among them, L indicates a long integer.
(3) Real Constants
Real constants have two forms of representation: decimal form and exponential form.
Decimal form: 5.4 0.074 -23.0 Exponential form: 5.4e0 4.3e-3 -3.3e4
(1) Real constants with a decimal part of 0 can be written as 453.0 or 453. (2) When using decimal representation, there must be numbers on both sides of the decimal point; it cannot be written as “.453“ and “453.”, but should be “0.453“ and “453.0“. (3) In exponential notation, there must be a number before e, and the exponent after e must be an integer (note: integer exponents can be positive, negative, or can be octal or hexadecimal, but must be integers).
(4) Character Constants
Character constants are marked by a pair of single quotes ‘ ’, and in C language, there are two types of character constants:
(1) A single character enclosed in a pair of single quotes, such as ‘a’, ‘r’, ‘#’. Note: ’a’ and ’A’ are two different character constants.
(2) A pair of single quotes enclosing a character starting with a backslash ollowed by several digits or letters, such as ‘
’, where “\