In-Depth Analysis of GESP Certification C++ Questions for September 2025 (Multiple Choice)

1、After executing the followingC++ code, the value of c is ( ).

int a = 10, b = 3;double c = a / b;

A. 3.33333

B. 3.333

C. 3.0

D. 3.3

【Analysis】

AnswerC

Key PointInteger Division and Type Conversion

Analysis

a / b is integer division, resulting in3 (the decimal part is truncated)

Integer3 is then assigned to the double variable c, converting it to 3.0

Trap:It is easy to mistakenly believe that floating-point division will occur automatically

Correct waydouble c = (double)a / b; or double c = a * 1.0 / b;

2、Among the followingC++ expressions, the one that evaluates to true is ( ).

A. (5 <= 5) && (7 < 5)

B. !(10 > 5)

C. (10 != 10) || (5 >= 3)

D. (5 == 3) && (4 > 2)

【Analysis】

AnswerC

Key PointLogical Operators and Boolean Operations

Analysis

A: (5<=5)→true, (7<5)→false, true&&false→false

B: !(10>5)→!true→false

C: (10!=10)→false, (5>=3)→true, false||true→true

D: (5==3)→false, (4>2)→true, false&&true→false

Preparation SuggestionMaster the short-circuit characteristics of logical operators.

3、The following statements aboutC++ arrays are incorrect ( ).

A. Array indices typically start from 0 .

B. int arr[5]; declares an array containing5 integers.

C. The size of an array must be determined at compile time and cannot use variables to define size.

D. It is possible to access the last element of the int arr[5]; array using arr[5] .

【Analysis】

AnswerD

Key PointArray Indexing and Boundaries

Analysis

An array int arr[5] has valid indices from0 to 4

arr[5] is an out-of-bounds access, which is undefined behavior

C option is not entirely correct in C++ (C++ supports dynamic arrays), but compared to D option, D is clearly incorrect

NoteOut-of-bounds access is a common programming error.

4、After executing the followingC++ code, the value of the variable sum is ( ).

int sum = 0;for (int i = 1; i &lt;= 5; i += 2){  sum += i;  int sum=0;}

A. 6

B. 9

C. 15

D. Infinite Loop

【Analysis】

AnswerB

Key PointLoops and Variable Scope

Analysis

The loop variable i takes values:1, 3, 5

sum accumulates:0+1=1 → 1+3=4 → 4+5=9

The inner int sum=0 is a new local variable, which does not affect the outer sum

TrapBe aware of nested variable scopes.

5、To correctly define a function that returns the larger of two integers max , it should use ( ).

A. void max(int a, int b) { return a > b ? a : b; }

B. int max(int a, int b) { if (a > b) return a; else return b; }

C. int max(a, b) { if (a > b) return a; else return b; }

D. void max(a, b) { cout << (a > b ? a : b); }

【Analysis】

AnswerB

Key PointFunction Definition and Return Values

Analysis

A:Return type isvoid but uses return to return a value, incorrect

B:Correct, returnsint type, with a clear return value

C:Parameter type declaration is missing, incorrect

D:Return type isvoid and parameters have no type, incorrect

Preparation SuggestionFunction definitions should be complete and standardized.

6、After executing the followingC++ code, the content of the array arr is ( ).

int arr[4] = {1, 2, 3};arr[3] = arr[0] + arr[2];

A. {1, 2, 3, 3}

B. {1, 2, 3, 4}

C. {1, 2, 3, 5}

D. {1, 2, 3, 6}

【Analysis】

AnswerB

Key PointArray Initialization and Assignment

Analysis

When partially initialized, remaining elements are automatically initialized to0

arr[0]=1, arr[2]=3, 1+3=4

The final array:{1,2,3,4}

NoteRules for partial initialization of arrays.

7、The following statements aboutC++ functions are correct ( ).

A. Functions must have parameters.

B. Functions can only return one value through return statement. However, multiple values can be returned through many indirect ways.

C. The main function can be called by other functions.

D. Function definitions can be directly nested, meaning one function can truly define another function inside it.

【Analysis】

AnswerB

Key PointFunction Characteristics

Analysis

A:Functions can have no parameters, incorrect

B:Correct, multiple values can be returned through reference parameters, pointers, structures, etc.

Cmain function is the program entry point and should not be called by other functions, incorrect

DC++ does not support nested function definitions, incorrect

Knowledge ExpansionCommon methods for returning multiple values.

8、The followingC++ code count++ executes ( ).

int i = 10;int count=0;while (i &gt; 0){  i -= 3;  continue;  count++;}

A. 2

B. 3

C. 4

D. 0

【Analysis】

AnswerD

Key PointEffect of the continue Statement

Analysis

continue statement skips the remaining code of the current loop

count++ is after continue, so it will never execute

The loop executes normally, but count remains 0

TrapCode after continue will not execute.

9、The output of the followingC++ code segment is ( ).

for (int i = 0; i &lt; 4; i++){  for (int j = 0; j &lt;= i; j++)  {    cout &lt;&lt; j;  }  cout &lt;&lt; "#";}

A. 0#01#012#0123#

B. 1#12#123#1234#

C. 0#1#2#3#

D. 0#01#012#01243#

【Analysis】

AnswerA

Key PointNested Loops and Output Format

Analysis

i=0: j=0 → Output“0#”

i=1: j=0,1 → Output“01#”

i=2: j=0,1,2 → Output“012#”

i=3: j=0,1,2,3 → Output“0123#”

NoteThe inner loop outputs the value of j.

10、The following statements aboutC++ variable scope are incorrect ( ).

A. Variables declared in for loop statements have a scope limited to that loop body.

B. Variables declared inside a function (local variables) are only valid within that function.

C. Variables declared outside all functions are valid throughout the entire program.

D. Local variables in different functions can have the same name, representing different memory units.

【Analysis】

AnswerC

Key PointVariable Scope

Analysis

C:Incorrect,Global variable scope starts from the declaration to the end of the file, not the entire program

Other options correctly describe their respective scope rules

Knowledge ExpansionThe extern keyword is used to extend the scope of global variables.

11、The following code’s statement is correct ( ).

int reversed = 0;while (x != 0){  int digit = x % 10;  x /= 10;  reversed = reversed * 10 + digit;}

A. Can reverse any integer of any digit

B. The maximum positive integer that can be reversed is2147483647

C. The maximum positive integer that can be reversed is2147483648

D. The maximum positive integer that can be reversed is1463847412

【Analysis】

AnswerD

Key PointInteger Reversal and Overflow Issues

Analysis

The code can reverse integers, but there is a risk of overflow

2147483647 when reversed becomes7463847412, exceedingint range(2147483647)

1463847412 when reversed becomes2147483641, withinint range

The maximum safely reversible number is1463847412

Trap:Integer overflow is a common boundary condition issue.

12、The following C++ code attempts to find the maximum value in an array, the underlined part should be filled in ( ).

int findMax(int arr[], int size){  int maxVal = ________; //underlined part  for (int i = 1; i &lt; size; i++)  {    if (arr[i] &gt; maxVal)    {      maxVal = arr[i];    }  }  return maxVal;}

A. 0

B. arr[-1]

C. arr[0]

D. size

【Analysis】

AnswerC

Key PointAlgorithm Initialization

Analysis

When finding the maximum value, the initial value should be set to an element in the array

arr[0] is the most suitable initial value

Setting it to0 may be incorrect (if the array is all negative)

arr[-1] is illegal access

Best PracticeInitialize with the first element of the array.

13、The following statements aboutC++ functions are correct ( ).

A. Function parameter passing has only one way: value passing.

B. Function parameters still occupy memory space after the function call ends

C. A function without a return value must be declared asvoid type and cannot contain return statement

D. C++11 and later standards require functions to explicitly declare return types, not allowing default return int

【Analysis】

Answer:D

Key PointFunction Parameters and Memory Management

Analysis

A:Incorrect,C++ supports three parameter passing methods: ①Value Passing: passing a copy of the parameter; ②Reference Passing: passing a reference to the parameter; ③Pointer Passing: passing the address of the parameter.

B:Incorrect, the lifetime of parameters is limited to the function execution period, and the memory for parameters is released after the function call ends

C:Incorrect,void functions can contain return; (no return value)

D:Correct,C++11 and later standards require all functions to explicitly declare return types; omitting the return type will lead to a compilation error; this is to improve code clarity and type safety

NoteUnderstand historical compatibility.

14、The following C++ code contains several errors ( ).

int main(){  const int SIZE = 5;  int arr[SIZE];  for (int i = 0; i &lt;= SIZE; i++)  {    arr[i] = i * 2;  }  cout &lt;&lt; arr[SIZE] &lt;&lt; endl;  return 0;}

A. 0 at

B. 1 at

C. 2 at

D. 3 at

【Analysis】

AnswerC

Key PointArray Boundary Checking

Analysis

Two out-of-bounds accesses: loop conditioni<=SIZE and arr[SIZE]

Valid indices are0 to 4, but index 5 is accessed

Common errorConfusing array size with maximum index.

15、The following statements aboutC++ string class and character arrays( char[] ) are incorrect ( ).

A. string objects can be assigned using = , while character arrays need to use strcpy .

B. string object’s length can be obtained usinglength() member function, while character arrays need to use strlen() function.

C. string objects are dynamically allocated in memory, thus can automatically handle changes in string length.

D. string objects and character arrays can both use == operator to directly compare whether two strings are equal.

【Analysis】

AnswerD

Key PointComparison of string class and character arrays

Analysis

D:Incorrectstring class overloads the == operator, but character arrays use == to compare addresses

Character array comparison should usestrcmp()

Other options correctly describe the differences between the two

Preparation SuggestionMaster the convenience of the string class

Overall Preparation Suggestions

1. Key Content to Master

1、Type Conversion:Integer Division, Implicit Type Conversion

2、Array Operations:Index Boundaries, Initialization Rules

3、Function Design:Parameter Passing, Return Values, Scope

4、Control Flow:Loops, Conditions, Jump Statements

5、String Handlingstring class and character array differences

2. Summary of Common Mistakes

1、Truncation characteristics of integer division

2、Array indices start from0, maximum index issize-1

3continue skips the remaining code of the current loop

4、Character arrays cannot be directly compared using== to compare contents

3. Learning Methods

1、Write more code to verify understanding

2、Pay attention to boundary conditions and special cases

3、Understand the essence of concepts rather than rote memorization

4、Master debugging skills to locate issues

Leave a Comment