【Point 1】C Program
There are three structures in C language programs: sequential structure, loop structure (three types of loops), and selection structure (if and switch).
【Point 2】main Function
In every C language program, there is exactly one main function. The program starts from the main() entry point and reads from top to bottom (executing loops when encountered, making selections when encountered).
【Point 3】Storage Form
Data in a computer is stored in binary form. The smallest storage unit is a bit, which is composed of 0 or 1. A byte refers to eight bits. The location where data is stored is its address.
【Point 4】Comments
Comments are explanations of the program and can appear anywhere appropriate in the code. Comments start with “/*” and end with the nearest “*/”; any content in between will not be executed by the computer, and comments cannot be nested.
【Point 5】Writing Format
Every statement must end with a semicolon, which is part of the statement. Multiple statements can be written on one line, and one statement can be split across multiple lines.
【Point 6】Identifiers
Valid user identifiers are composed of letters, numbers, and underscores. Any other elements are incorrect. The first character must be a letter or an underscore. Starting with a number is incorrect. C language identifiers fall into three categories: (1) keywords. They have fixed meanings in the program and cannot be used for other purposes, such as int, for, switch, etc. (2) predefined identifiers. Identifiers that are predefined and have specific meanings, such as define, include, etc. (3) user-defined identifiers. Identifiers defined by the user according to their needs, which comply with naming rules and are not the same as keywords. Keywords cannot be used as user identifiers. main, define, scanf, printf are not keywords. The confusing part is that If can be a user identifier. Because the first letter of If is capitalized, it is not a keyword.
【Point 7】Real Data Types
Valid forms of real data include: decimal form and exponential form. Understand how to determine the validity of exponential forms. 2.333e-1 is valid, and the data is 2.333×10^-1. Exam mnemonic: there must be numbers before and after e, and the number after e must be an integer.
【Point 8】Characters
Valid forms of character data: ‘1’ is a character occupying one byte, while “1” is a string occupying two bytes (including an ending symbol). The ASCII value of ‘0’ is 48, ‘a’ is 97, and ‘A’ is 65. Characters and integers are closely related: char a = 65; printf(“%c”, a); the output will be: a printf(“%d”, a); the output will be: 65 Generally, the incorrect representation of a single character in exams is: ’65’ “1” Characters can be involved in arithmetic operations, remember: ‘0’-0=48 The method to convert between uppercase and lowercase letters: ‘A’+32=’a’ they generally differ by 32.
【Point 9】Integer Data Types
Integers are generally two bytes, characters are one byte, and doubles are generally four bytes: In exams, it is often stated that in a 16-bit compilation system or a 32-bit system. In such cases, do not worry, just solve the problems. Understanding that integers are generally two bytes, characters are one byte, and doubles are generally four bytes is sufficient.
【Point 10】Escape Characters
Escape characters are examined as follows: In the program int a = 0x6d, a hexadecimal number is assigned to variable a. Note that 0x must be present. In the program int a = 06d, it is an octal form. In escape characters, ‘m’ is valid, 0 cannot be written, and x must be lowercase. ‘a’ is valid, 0 cannot be written. ‘8’ is invalid because 8 cannot appear.
【Point 11】Arithmetic Operations
There are five arithmetic operators: +, -, *, /, %. The % symbol requires integers on both sides. If not integers, it is incorrect. There are three cases of truncating decimals: It is not rounding but discarding the decimal part. 1. int a =1.6; 2. (int)a; 3. 1/2; 3/2;
【Point 12】Type Casting
Converting an operand to a specified type, formatted as (type name) expression must be (int)a not int(a), note that the type must have parentheses. Note the difference between (int)(a+b) and (int)a+b. The former converts a+b, while the latter converts a and then adds b.
【Point 13】Assignment
There must be a value for an expression. Assignment expression: The value of the expression is the leftmost value, a=b=5; this expression equals 5, constants cannot be assigned. Compound assignment operators: Note: a*=m+2 is a=a*(m+2) Increment and decrement expressions: Assume a=5, ++a (value of expression is 6), a++ (value of expression is 5); j=a++; is equivalent to j=a;a=a+1; while j=++a; is equivalent to a=a+1;j=a;. Exam mnemonic: ++ before means increment before use, ++ after means use before increment.
【Point 14】Comma Operator
Comma expressions: have the lowest priority; the value of the expression is the value of the rightmost expression. The value of the expression (2,3,4) is 4.
【Point 15】Base Conversion
It is essential to remember how to convert binary to decimal. Octal does not have 8, carry 1 for every 8, and the value of 018 is invalid.
【Point 16】Bitwise Operations
There will be one or two exam questions on this topic. C language provides six bitwise operators: bitwise NOT ~, left shift <<, right shift >>, bitwise AND &, bitwise XOR |, bitwise OR ^. Overall processing method: Almost all bitwise operation questions should be processed by converting decimal to binary and then back to decimal. The rule of XOR operation: 0 XOR 1 equals 1, 0 XOR 0 equals 0, 1 XOR 1 equals 0. Can be remembered as “same is 0, different is 1”. When data is not discarded, << left shift means multiply by 2;> right shift means divide by 2.
Special statement: The content of this article is sourced from the internet, and copyright belongs to the original author.
Youdao Exam God Computer Level 2
7-Day Summer Rescue Training Camp
Detailed explanation of key points, master core points
Free genuine question bank, practice with more peace of mind
Group of 3
As low as 0.1 yuan!
Quickly gather your friends
Learn together
Improve together!
[Scan to join the group, pass level 2 at once]