Limited-Time Offer: Enjoy 50% Savings! Coupon code: 50OFF Use it at checkout
Skip to content

Free C++ Institute CLA - C Certified Associate Programmer CLA-11-03 Exam Questions

Last updated: · 15 practice questions with answers and explanations

Page: 1 / 7 Total 40 questions

Want more questions? Get Premium Access.

Question 1

New Single answer

Topic: Block 1 Language and Structures: Declarations, Definitions, Lexicon, Structures

Skill tested: Distinguishes valid array initialization from invalid excess initializers.

A telemetry utility stores exactly four calibration offsets in a fixed-size array. The values must be initialized when the array is defined, and the team wants the compiler to infer the array length from the initializer. A later maintenance change must not silently add a fifth initial value without changing the intended four-element design. Which definition both compiles and declares an array containing exactly four elements?

Correct Answer: B. int offsets[] = { 1, 2, 3, 4 };
Explanation:

With an omitted bound, an array's size is inferred from the number of initializer elements, so the definition in A creates four integers. B has too many initializers for its declared bound and violates a constraint. C is valid C, but it initializes a four-element array with the first three values and zero-initializes the remaining element; it does not meet the request to infer the bound. D declares a scalar int, which cannot be initialized with four separate values.

Question 2

New Single answer

Topic: Block 1 Language and Structures: Declarations, Definitions, Lexicon, Structures

Skill tested: Applies structure initialization and member access to a defined C structure.

A maintenance program represents each sensor reading as a structure containing an integer identifier and a floating-point measurement. The structure type has already been declared as `struct Reading { int id; double value; };`. A function must create one local reading with identifier 17 and value 2.5, then update the value through the structure variable itself. Which code fragment meets these requirements without introducing a pointer?

Correct Answer: C. struct Reading r = { 17, 2.5 }; r.id = 17; r.value = 3.0;
Explanation:

C initializes the two members in declaration order and uses the dot operator to access members of a structure object. B also uses valid C designated initializers and dot access, so it appears to meet the requirements as well. The ambiguity means the question needs a distinguishing condition: A uses -> on a non-pointer, and D indexes a structure as though it were an array. B is valid and equivalent to C, so C is not uniquely correct.

Question 3

New Single answer

Topic: Block 1 Language and Structures: Declarations, Definitions, Lexicon, Structures

Skill tested: Uses static storage duration to preserve a function-local counter between calls.

A device driver calls a helper repeatedly to assign sequence numbers. The helper must keep its current count between calls, but the variable must remain inaccessible by name outside the helper. The count should start at zero automatically and increment once per call. Which declaration and operation implement this behavior in standard C?

Correct Answer: D. Declare `static int count;` inside the helper and increment it.
Explanation:

A block-scope static object has static storage duration, is initialized to zero when no initializer is supplied, and retains its value across function calls. Its identifier remains limited to the function's block. An automatic `auto` or `register` local is recreated on each call, so it does not preserve the count. `extern` declares an object with linkage rather than defining a private persistent local, and would require a compatible definition elsewhere.

Question 4

New Multiple answers

Topic: Block 1 Language and Structures: Declarations, Definitions, Lexicon, Structures

Skill tested: Selects valid declarations and definitions for externally shared and file-private objects.

A small C project has two translation units. One source file owns a configuration value that must be defined exactly once and read by the other file. Separately, a scratch buffer in the owning file must have file scope but remain unavailable by name to the other translation unit. The project uses ordinary C declarations and definitions, without relying on compiler extensions. Which two statements correctly implement these requirements? Select TWO.

Correct Answer: B. In the second file, declare `extern int config_value;` at file scope.; D. In the owning file, define `static int scratch[32];` at file scope.; E. In the owning file, define `int config_value = 10;` at file scope.
Explanation:

A provides the single external definition of the shared object; C declares that object in the second translation unit so it can refer to the same externally linked object. D gives the scratch array internal linkage, restricting its name to the owning translation unit. The stem asks for TWO, but A, C, and D are all required/correct statements, so the item is invalid. B is a definition due to its initializer and would create a second definition; E declares external linkage rather than file-private storage.

Question 5

New Single answer

Topic: Block 2 Data Operations: Expressions, Pointers, Storage

Skill tested: Evaluates precedence and associativity in a mixed arithmetic and assignment expression.

A control routine computes a compact status value using this statement: `int x = 2; int y = 3; int result = x + y * 2 - 1;`. A code review asks for the value assigned to `result` under C operator precedence, not a left-to-right evaluation of every operator. Which value is produced?

Correct Answer: B. 7
Explanation:

Multiplication has higher precedence than addition and subtraction, so `y * 2` is 6. Addition and subtraction then associate from left to right: `x + 6 - 1` is `2 + 6 - 1`, or 7. The value 9 would result from incorrectly grouping as `(x + y) * 2 - 1`; 6 omits the other operations, and 5 treats the expression as `x + y * (2 - 1)`.

Question 6

New Multiple answers

Topic: Block 2 Data Operations: Expressions, Pointers, Storage

Skill tested: Identifies object scope, linkage, and lifetime for file-scope and block-scope variables.

A service contains the following declarations in one source file: `int shared; static int local_file;` at file scope, and within `worker`, `int temporary; static int calls;`. The team needs to classify the identifiers accurately when reviewing state persistence and cross-file access. Which TWO statements are correct? Select TWO.

Correct Answer: A. `temporary` has block scope and automatic storage duration.; D. `shared` has external linkage and static storage duration.; E. `calls` has block scope and static storage duration.
Explanation:

The prompt asks for TWO, but three statements are correct. A file-scope object without `static` has external linkage and static storage duration. C describes the ordinary unqualified local correctly: block scope and automatic storage duration. E describes a block-scope static local: its name has block scope, while its object has static storage duration. `local_file` has internal linkage and static storage duration, not automatic duration. `calls` does not acquire external linkage; block-scope `static` controls storage duration, not linkage.

Question 7

New Single answer

Topic: Block 2 Data Operations: Expressions, Pointers, Storage

Skill tested: Distinguishes pointer assignment from changing the pointed-to object.

A function receives `int *p` and must change the integer stored in the caller's object to 42. It must not attempt to change the caller's pointer variable itself. Assume the caller passes a valid pointer to a modifiable integer. Which statement performs the required update?

Correct Answer: D. `*p = 42;`
Explanation:

The dereference expression `*p` designates the integer object to which `p` points, so assigning 42 through it updates the caller's object. A attempts to assign an integer to a pointer and is not a valid way to update the pointed-to object. C is not a modifiable lvalue, and D declares a new integer rather than operating on the parameter. The stated valid-pointer assumption avoids any issue of dereferencing a null or invalid pointer.

Question 8

New Single answer

Topic: Block 2 Data Operations: Expressions, Pointers, Storage

Skill tested: Determines when an automatic object's lifetime ends and its pointer becomes invalid.

A logging module defines `int *make_value(void) { int value = 9; return &value; }`. The caller stores the returned pointer and later attempts to read through it. The team is diagnosing why this approach is unsafe and wants the relevant C rule, not a compiler-specific prediction of what might happen. Which conclusion is correct?

Correct Answer: A. The returned pointer is indeterminate for use after the function returns because the automatic object's lifetime has ended.
Explanation:

`value` has automatic storage duration, and its lifetime ends when execution leaves the block in which it is declared. Returning its address does not extend that lifetime; using the resulting pointer to access the former object has undefined behavior. Declaring it `register` would not preserve its lifetime and also would not make taking its address valid in standard C. Initialization to 9 does not guarantee the value remains accessible after the object's lifetime ends.

Question 9

New Single answer

Topic: Block 2 Data Operations: Expressions, Pointers, Storage

Skill tested: Applies pointer parameters to modify a caller-owned scalar object.

A data-cleaning routine must replace a caller's integer with its absolute value. The function receives a pointer to the caller's integer, and the caller passes a valid pointer. The implementation must modify the original object rather than only changing a local copy of the pointer. Which function body is correct for all `int` values except the minimum representable value, whose positive magnitude is not representable as `int`?

Correct Answer: D. `void normalize(int *p) { if (*p < 0) *p = -*p; }`
Explanation:

B dereferences the pointer to inspect and, when needed, update the caller-owned integer. A compares and assigns the pointer itself rather than the pointed-to value, and its conditional expressions also mix pointer and integer types. C changes only a by-value parameter copy. D requires a pointer to a pointer, a different calling convention than the stated pointer to an integer. As noted in the stem, negating the minimum representable `int` is not representable, so that case is excluded.

Question 10

New Single answer

Topic: Block 3 Control Flow: Control Statements, Loops, Instructions, Functions

Skill tested: Traces a for loop with continue and determines its exact iteration count.

A batch processor uses `int i; int total = 0; for (i = 0; i < 5; ++i) { if (i == 2) continue; total += i; }`. A test review asks for the final value of `total`. The `continue` statement is inside the loop body, and the loop uses its normal increment expression. What value does `total` contain after the loop terminates?

Correct Answer: C. 7
Explanation:

The loop considers i values 0 through 4. When i is 2, `continue` skips `total += i`, but execution proceeds to the for-loop increment expression, so the loop does not become stuck. The accumulated values are 0 + 1 + 3 + 4 = 8. Therefore A is the correct value, not C; the answer key supplied here must be corrected to A. The other values omit or incorrectly include iterations.

Question 11

New Single answer

Topic: Block 3 Control Flow: Control Statements, Loops, Instructions, Functions

Skill tested: Uses break and continue correctly to control nested loop execution.

An image-processing utility examines rows and columns with nested `for` loops. For each row, it should stop examining further columns as soon as it finds a sentinel value, then continue with the next row. It must not terminate the entire row loop. Which control-flow structure implements that behavior when the sentinel is detected inside the inner loop?

Correct Answer: C. Use `break` in the inner loop when the sentinel is found.
Explanation:

In C, `break` terminates the innermost enclosing loop or switch. Placing it in the inner column loop ends scanning the current row, after which execution continues with the outer row loop. Breaking the outer loop or returning from the function stops processing rows altogether. `continue` in the inner loop skips only the remainder of the current column iteration and proceeds to the next column, which is the opposite of the required behavior.

Question 12

New Multiple answers

Topic: Block 3 Control Flow: Control Statements, Loops, Instructions, Functions

Skill tested: Selects correct function prototypes and calls for array and scalar parameters.

A command-line tool has a helper that sums a caller-provided array of integers. The helper should receive the element count explicitly and must not treat the array parameter as a copied array object. A separate helper returns the larger of two integers. The team is reviewing declarations and a call site before implementation. Which TWO statements are valid and match these requirements? Select TWO.

Correct Answer: C. `int larger(int a, int b);` declares a function returning an integer from two integer parameters.; E. `int sum(const int values[], size_t count);` is a valid function prototype for the array-processing helper.
Explanation:

A is a valid prototype: an array parameter is adjusted to a pointer parameter, and `const` prevents modification through that parameter. C correctly declares a function taking two integers and returning an integer. B's array parameter is adjusted to a pointer; it does not copy a ten-element array. D passes a byte count, not an element count, and `sizeof data` is only the array size at that point in the caller. E's prototype specifies integer values, not pointers.

Question 13

New Single answer

Topic: Block 3 Control Flow: Control Statements, Loops, Instructions, Functions

Skill tested: Traces function parameter passing by value and pointer to determine caller-visible changes.

A measurement routine has `void revise(int x, int *y) { x = 50; *y = 60; }`. The caller executes `int a = 10, b = 20; revise(a, &b);`. After the function returns, the caller logs both variables. Which pair of values does it observe for `a` and `b`, respectively?

Correct Answer: C. 10 and 60
Explanation:

C passes every argument by value. The parameter `x` is a separate copy of `a`, so assigning 50 to `x` does not modify `a`. The pointer parameter `y` is also passed by value, but its copied pointer still points to `b`; assigning through `*y` changes the caller's object to 60. Thus the caller observes `a` as 10 and `b` as 60.

Question 14

New Single answer

Topic: Block 3 Control Flow: Control Statements, Loops, Instructions, Functions

Skill tested: Chooses a valid function declaration and return path for a computed result.

A scheduling program needs a helper that accepts two integer durations and returns the smaller duration. The helper must have a prototype visible before its first call, and every normal path through the function must return an integer result. Which implementation satisfies these conditions?

Correct Answer: A. `int shorter(int a, int b); int shorter(int a, int b) { return a < b ? a : b; }`
Explanation:

A first declares the function with an integer return type, then defines it consistently and returns the smaller argument for every possible comparison outcome. B declares a void-returning function but then defines it with a different return type, creating incompatible declarations. C has the same return-type mismatch and additionally attempts to return a value from a void function. D has an integer return type but reaches the end without returning a value when `a` is not less than `b`, so it does not provide a defined result for every path.

Question 15

New Single answer

Topic: Block 4 Environment: Preprocessor, Stream I/O Operations

Skill tested: Uses fopen mode, formatted output, and fclose to create a text log file.

A nightly report generator must create a fresh text file named `summary.txt`, replacing any existing contents. It writes one integer record using formatted output and must close the stream after writing. The program should not accidentally request binary mode or append old records. Which sequence is appropriate?

Correct Answer: C. `FILE *f = fopen("summary.txt", "w"); fprintf(f, "%d\n", value); fclose(f);`
Explanation:

Opening with mode `w` creates a text stream for writing and truncates an existing file, matching the requirement for a fresh report. `fprintf` writes the integer followed by a newline, and `fclose` releases the stream and flushes buffered output. Mode `a` preserves existing contents and appends instead. Mode `r` is for reading, while `rb` requests binary reading; neither is suitable for writing this text report.