In-Depth Analysis of GESP Certification C++ Level 3 Questions (True/False) – September 2025

1、Expression sizeof(‘a’) always results in 1 , because ‘a’ is a character.

【Analysis】

Answer×

Key PointType of character literal andsizeof behavior

Analysis

InC++, the type of character literal‘a’ ischar,sizeof(char) guarantees1

However inC, character literals areint type,sizeof(‘a’) may be4

Since the question clearly states it isC++, the result is indeed1, but the statementalways is inaccurate, becauseC language differs

NoteC andC++ have differences in character literal types.

2、InC++, all global variables, if not explicitly initialized, will be automatically initialized to0.

【Analysis】

Answer

Key PointInitialization rules for global variables

Analysis

Global variables and static variables have static storage duration

If not explicitly initialized: basic types (int,float etc.) are initialized to0; pointer types are initialized tonullptr; class types call the default constructor

TrapLocal variables are not automatically initialized, values are undefined.

3、The statement do { … } while (false); will execute the statements in the loop body at least once.

【Analysis】

Answer

Key Pointdo-while loop characteristics

Analysis

Thedo-while loop executes the loop body first, then checks the condition

Even if the condition is initiallyfalse, the loop body is executed at least once

while(false) causes the loop to execute only once before exiting

Application scenarioCommonly used in macro definitions to create scope.

4、InC++, ++i is a left-value expression, while i++ is a right-value expression.

【Analysis】

Answer

Key PointReturn value types of prefix and postfix increment operators

Analysis

++i returns a reference to the variable, which is a left-value (can appear on the left side of an assignment)

i++ returns a temporary value, which is a right-value (cannot appear on the left side of an assignment)

int i = 0;++i = 5;// Valid, i becomes 5i++ = 5;// Invalid, compilation error

5、Forenum Color { RED, GREEN, BLUE }; , RED has the typeint.

【Analysis】

Answer×

Key PointBase type of enumeration type

Analysis

InC++, the type of enumeration items is the enumeration type itself (Color), notint

Although enumeration items have corresponding integer values, the types are different

C++11 introduced scoped enumerations:enum class Color { RED, GREEN, BLUE };

Color c = RED;// c's type is Color, not int

6、The macro definition#define SQUARE(x) x * x is not a safe macro definition, SQUARE(2+3) will incorrectly calculate 25 .

【Analysis】

Answer×

Key PointTraps in macro definitions

Analysis

SQUARE(2+3) expands to2+3 * 2+3, resulting in2+6+3=11, not25

Correct usage:#define SQUARE(x) ((x) * (x))

Even with parentheses,SQUARE(i++) still has side effect issues

Best practiceUse inline functions instead of macros.

7、InC++, the value range of char type is always -128 to 127.

【Analysis】

Answer×

Key PointSign of char type

Analysis

char sign is defined by the implementation, it can besigned char orunsigned char

Three types ofchar types:signed char: -128 to127; unsigned char: 0 to255; char: determined by the compiler, can besigned orunsigned

Usestd::numeric_limits<char>::is_signed to check.

8、The expression a > b ? a : b = 10; is not necessarily validC++ code.

【Analysis】

Answer×

Key PointPrecedence and associativity of the conditional operator

Analysis

The expression resolves to(a > b ? a : b) = 10;

Ifa>b, it attempts to assigna, but ifa is a right-value, it is illegal

Ifa≤b, it attempts to assignb, but ifb is a right-value, it is illegal

int a=1, b=2;(a &gt; b ? a : b) = 10;// May be valid, depends on whether a,b are left-values// But if it is: (a &gt; b ? 1 : b) = 10;// Invalid, 1 is a right-value

9、The statements#include “file.h” and #include <file.h> have different search strategies when the compiler looks for header files.

【Analysis】

Answer×

Key PointDifferences in search paths for header file inclusion

Analysis

#include “file.h” searches the current directory first, then the system directory

#include <file.h> directly searches the system directory

The specific search paths are defined by the compiler implementation

Best practiceUse<> for system header files, and“” for custom header files.

10、In the same scope, extern declared variables can be defined multiple times.

【Analysis】

Answer×

Key PointFunction of the extern keyword

Analysis

extern is used to declare variables, not define them

Variables can only be defined once, but can be declared multiple times withextern

Violating theone definition rule“(ODR) will lead to linking errors

extern int a; // Declarationextern int a;// Re-declaration, allowedint a = 10; // Definition, can only be once

Core Knowledge Summary

1. Confusing Concepts

1C andC++ differences:Different types of character literals

2、Initialization rules:Globalvs local variables

3、Operator characteristics:Return values of prefix and postfix increments

4、Type system:Actual type of enumeration items

2. Common Traps

1、Macro definitions:Parameter expansion issues

2char type:Sign uncertainty

3、Operator precedence:Traps of the conditional operator

4、Header file inclusion:Differences in search paths

3. Exam Preparation Suggestions

1、Understand the difference between standards and implementations

2、Master the precise semantics of various constructs

3、Pay attention to historical compatibility issues

4、Validate understanding through code practice

Leave a Comment