Key details for this exam, checked against the published exam outline
Each question shows the correct answer and an explanation of why it is right
A developer is reviewing a legacy module and finds the following code fragment at file scope, followed by its use inside two different functions in the same file:
int counter;
void increment(void) {
extern int counter;
counter++;
}
void reset(void) {
counter = 0;
}Which statement correctly describes the roles of int counter; at file scope and extern int counter; inside increment?
At file scope, int counter; without an initializer is a tentative definition that also allocates storage, making it both a declaration and a definition. The extern int counter; inside increment is just a declaration telling the compiler that counter already exists elsewhere with external linkage; it does not allocate new storage or create a local variable. Therefore both statements refer to the same single object, and there is no duplicate definition or linker error.
A student writes the following code to store and print student scores using an array of structs:
struct Student {
char name[10];
int score;
};
int main(void) {
struct Student list[2] = {
{"Ann", 90},
{"Bob", 85}
};
printf("%s scored %d\n", list[1].name, list[1].score);
return 0;
}What will this program print?
The array list is properly initialized with two struct elements using nested brace initializers, which is valid C syntax for array-of-struct initialization. list[1] refers to the second element, which holds the name "Bob" and score 85. So the program prints "Bob scored 85". The other options misidentify the index or incorrectly claim a compile error or undefined behavior, neither of which applies here.
A programmer writes the following code to swap the values pointed to by two integer pointers:
void swap(int *a, int *b) {
int temp;
temp = *a;
*a = *b;
*b = temp;
}
int main(void) {
int x = 5, y = 10;
swap(&x, &y);
printf("%d %d\n", x, y);
return 0;
}What is the output of this program, and why?
In C, arguments are always passed by value, but when the arguments are pointers, the values being copied are addresses. This allows the function to dereference those addresses and modify the objects they point to, effectively achieving call-by-reference semantics. Inside swap, *a and *b refer directly to x and y in main, so their values are exchanged, producing 10 5. The claim about global variables is irrelevant since x and y are local to main, and temp is properly assigned before being used, so there is no undefined behavior.
A developer writes a loop intended to search an array for a target value and stop as soon as it is found, skipping over negative sentinel values without counting them as valid data:
int arr[] = {3, -1, 7, -1, 9, 2};
int target = 9;
int i, found = 0;
for (i = 0; i < 6; i++) {
if (arr[i] < 0) {
continue;
}
if (arr[i] == target) {
found = 1;
break;
}
}What is the value of found and the value of i immediately after the loop finishes execution?
The loop iterates through the array. When arr[i] is negative, continue skips the rest of the loop body but still lets the for loop's increment step (i++) run normally, so it is not an infinite loop. Checking each index: i=0 (3, not target), i=1 (-1, skipped), i=2 (7, not target), i=3 (-1, skipped), i=4 (9, matches target) sets found=1 and break exits the loop immediately, so i remains 4 at that point. Thus found = 1 and i = 4.
A configuration header uses conditional compilation to control debug output across different build types:
#define DEBUG_LEVEL 2
#if DEBUG_LEVEL > 1
#define LOG(msg) printf("DEBUG: %s\n", msg)
#else
#define LOG(msg)
#endif
int main(void) {
LOG("Starting process");
printf("Process running\n");
return 0;
}Given this code, what will be printed when the program runs?
Since DEBUG_LEVEL is defined as 2, the preprocessor evaluates the condition DEBUG_LEVEL > 1 as true, so LOG(msg) expands to printf("DEBUG: %s\n", msg). This means LOG("Starting process") becomes a call that prints "DEBUG: Starting process", followed by the normal execution of the next printf statement, which prints "Process running". The #if directive can indeed evaluate integer constant expressions involving macros defined via #define, so there is no compile error, and both printf statements execute sequentially since there is no early return or control flow interruption.
40 questions covering all exam domains, starting from $20
Exam domains verified against: Official C++ Institute CLA-11-03 exam guide, last checked September 2026.
Learn to identify valid variable declarations and understand the difference between declaring and defining variables. Master data structures like arrays and structs, storage classes such as auto and static, and the rules for naming identifiers in C.
Evaluate expressions using arithmetic, relational, logical, and bitwise operators while understanding type conversions and operator precedence. Work with pointers for declaring, initializing, and manipulating memory addresses, and manage arrays and memory layout effectively.
Sample question from this domain above: Q3
Use control statements including if, else, and switch to direct program execution. Implement loops with while, do-while, and for constructs, and declare functions with proper parameters and return values.
Sample question from this domain above: Q4
Apply preprocessor directives such as #define, #include, and #ifdef for conditional compilation and code organization. Perform file input and output using functions like fopen, fclose, and fprintf with proper format specifiers.
Sample question from this domain above: Q5
Common questions about the exam itself