1. Run the following program, the output result is ( ).
A.X0 B.X5 C.5 D.0
Knowledge points assessed: functions, local variables, and global variables.
2. Run the following program, the output result is ( ).
A.3 B.4 C.9 D.16Knowledge points assessed: simulation.i=1, satisfies the while statement, runs t=1, i=3;i=3, satisfies the while statement, runs t=2, i=5;i=5, satisfies the while statement, runs t=3, i=7;i=7, does not satisfy the while statement, outputs t=3.3. The result of the statement: cout<<(char)(‘F’+4) is ( ).A.I B.j C.K D.JKnowledge points assessed: character type operations.4. Among the following choices, the one with the highest precedence is ( ).A.+ B.- C.* D.=Knowledge points assessed: operation precedence.5. Regarding the new and delete keywords in C++, which of the following statements is incorrect ( ).
A. Memory allocated with new int[10] must be released with delete[] – Correct
B. int *p = new int; allocated integer memory is initialized to 0 by default – Incorrect (not initialized by default)
C. Using delete on a null pointer (nullptr) is safe and will not cause an error – Correct
D. new throws std::bad_alloc exception by default when memory allocation fails, rather than returning a null pointer – Correct
Based on the provided options and C++ memory management rules, the analysis is as follows:
-
A. Memory allocated with new int[10] must be released with delete[] – CorrectIn C++, memory allocated with
<span><span>new[]</span></span>must be released with<span><span>delete[]</span></span>to ensure all memory is correctly released and destructors (if any) are called. Using regular<span><span>delete</span></span>will lead to undefined behavior. Therefore, this statement is correct. -
B. int *p = new int; allocated integer memory is initialized to 0 by default – Incorrect (not initialized by default)This statement is incorrect. In C++,
<span><span>new int</span></span>does not initialize the allocated memory, which contains undefined garbage values. If initialization to 0 is needed,<span><span>new int()</span></span>must be used (value initialization). Therefore, the original statement “allocated integer memory is initialized to 0 by default” is incorrect. -
C. Using delete on a null pointer (nullptr) is safe and will not cause an error – CorrectThe C++ standard states that using
<span><span>nullptr</span></span>with<span><span>delete</span></span><span><span>is safe; the operation will be ignored and will not cause a runtime error. Therefore, this statement is correct.</span></span> -
D. new throws std::bad_alloc exception by default when memory allocation fails, rather than returning a null pointer – CorrectBy default,
<span><span>new</span></span>throws<span><span>std::bad_alloc</span></span><span><span>exception when memory allocation fails, rather than returning a null pointer. If a null pointer is needed,</span></span><code><span><span>new (std::nothrow)</span></span><span><span>must be used. Therefore, this statement is correct.</span></span>
Conclusion
The incorrect option is B, because<span><span>new int</span></span><span><span>allocated integer memory is not initialized to 0 by default.</span></span>
Programming 1: Celebration Queue


Programming 2: Tea Set Combination


Programming 3: Character Swap to Balance Odd and Even Positions


Programming 4: Layered Matrix Interleaved Rotation
Analysis:
The 1st layer (outer layer) rotates 90 degrees clockwise.
The 2nd layer (inner layer) rotates 90 degrees counterclockwise.
Input requirements
1. The first line inputs a positive integer n (2<=n<=100), representing the number of rows and columns of the matrix
2. The next n lines, each input n integers (-1000<=integer<=1000), representing the matrix elements, separated by spaces
Output requirements
Output n lines, each line containing n integers, representing the rotated matrix, separated by spaces.
Key points
1. Layer division: process layer by layer from outside to inside,
2. Alternating rotation direction: odd layers clockwise, even layers counterclockwise.
3. Center element: if n is odd, the center element does not rotate,
Data range
Matrix size: from 2×2 to 100×100.
Element value range: -1000 to 1000,
Sample input and output
Input:
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output:
13 9 5 1
14 6 7 2
15 10 11 3
16 12 8 4

Programming 5: Circular Coin GameTake Coins
Example explanation
First data set (n=1,a_1=10):
Jerry takes all 10 coins, Tom cannot take any, Jerry wins.
Second data set (n=2,a_1=30, a_2=50):
Jerry and Tom take turns taking coins, ultimately Tom wins (specific strategy needs further analysis).
Programming 6: Magic Card Arrangement

