Exam Information
Free practice questions with explanations
C++ Institute CLA-11-03 Practice Questions
Answer a question to see the correct answer and the explanation, or click Show answer. Newest questions first.
- Questions
- 11
- Answered
- 0
- Correct
- 0
- Score
- -
-
1 Question 1 Single choice Control Flow: Control Statements, Loops, Instructions, Functions
A developer is writing a loop that reads integers from a file until a sentinel value of -1 is found. The loop must be entered at least once regardless of the first value read, because the program prints a prompt before each read. The developer also wants to skip printing the summary when the input file is empty. Which construct, combined correctly, meets these requirements? The file handle is already open and checked for NULL before the loop begins. The team targets strict C99 with no compiler extensions, and code reviewers have flagged any use of goto for loop control as unacceptable in this codebase.
Correct Answer: BExplanationA do-while loop evaluates its controlling expression after the body executes, so the first read always happens, which satisfies the requirement to enter the loop at least once. Guarding the summary with an if statement on the count of values read handles the empty-file case. The while loop with a pre-read still needs a priming read and a duplicated prompt, which is awkward and error-prone. The goto variant is ruled out by the codebase rule against goto for loop control. The switch-based version prints the summary even for empty input, violating the stated requirement.
-
2 Question 2 Single choice Data Operations: Expressions, Pointers, Storage
A firmware engineer is extracting a 4-bit field from a 16-bit unsigned status register value stored in a variable of type unsigned short. The field occupies bits 5 through 8 inclusive, counting from bit 0 as the least significant bit. The engineer writes the expression (status >> 5) & 0xF and then, during code review, is asked to confirm that integer promotion does not alter the result on a target where int is 16 bits wide. The register is also compared to a signed int threshold of -1 elsewhere in the same function. Which statement about the extraction expression is correct? Assume standard C arithmetic conversion rules apply with no implementation-specific extensions.
Correct Answer: AExplanationAn unsigned short on a 16-bit int platform cannot be promoted to a larger type that changes its value; its values fit in int, so the usual promotions leave the value intact and the shift is a logical shift of a non-negative value. Bits 5 through 8 shifted down by 5 and masked with 0xF yield the 4-bit field correctly. The sign-extension claim is false because the promoted value is non-negative, so no sign bits are introduced. The cast-before-shift suggestion is unnecessary for correctness here. The comparison claim is wrong for the extraction itself and misreads the relational conversion, which concerns a separate operation rather than this expression.
-
3 Question 3 Single choice Environment: Preprocessor, Stream I/O Operations
A library header defines a debugging macro DEBUG_LOG that expands to a fprintf call writing to stderr. The header is included by several translation units. In one source file, the developer defines DEBUG as 0 before including the header, and in the header the macro is guarded by #ifdef DEBUG. Production builds are compiled with -DDEBUG so that logs appear during testing. The team discovers that logging is still active in a build where -DDEBUG was not passed and the source file contains #define DEBUG 0. Later the team wants all logging removed from release binaries with zero residual code. Which change is the best and most reliable? The build system cannot be modified to add new flags for the release configuration.
Correct Answer: CExplanationThe #ifdef test only checks whether DEBUG is defined, so a source file that defines DEBUG as 0 still enables the block, which explains the observed logging. Changing the guard to #if DEBUG evaluates the value, so a definition of 0 removes the block completely at preprocessing time with no residual code. Adding #undef after each include is fragile because it must be repeated everywhere and does not stop the definition in the including file from taking effect in the header's own scope. A runtime flag leaves code in the binary and still performs checks. An empty-statement macro in a release section relies on the release configuration being selected correctly and does not address the mis-set DEBUG value.
-
4 Question 4 Single choice Language and Structures: Declarations, Definitions, Lexicon, Structures
A team maintains a multi-file C project. A header file config.h is included by four source files. It currently contains the line int buffer_size = 512; The linker reports multiple definition of buffer_size errors once a fifth source file includes the header. The team wants buffer_size to be shared across all translation units as one object, initialised once, and kept out of the header's definitions so that each source file only refers to it. Additionally, a static counter named call_count inside one of the source files must retain its value across calls to a function and must not be visible to other files. Which combination of declarations is correct? The project compiles under C99 with a standard-conforming linker.
Correct Answer: CExplanationA header should contain only the declaration extern int buffer_size; while a single source file provides the definition with the initialiser, which gives one shared object with no duplicate definitions. Inside a function, a static local variable keeps its value across calls and has no linkage, so it is not visible to other files. Making buffer_size static in the header gives each file its own copy, which violates the single shared object requirement. An auto local is destroyed on each return, so it cannot retain its value. An extern declaration with an initialiser is a definition that will produce the same duplicate definition error, and a file-scope static counter is not restricted to one function as the stem requires.
-
5 Question 5 Single choice Control Flow: Control Statements, Loops, Instructions, Functions
A function named find_first_negative scans an integer array and returns the index of the first negative element, or -1 when none exists. A colleague has written a nested loop that uses a flag variable to exit the outer loop. The function is called inside a hot path in a real-time signal processor, where the array holds up to 4096 samples and the call happens thousands of times per second. The colleague's version is correct but the reviewer wants the simplest construct that stops searching immediately upon finding the first match and keeps the code readable. Which implementation best meets these requirements? The function signature must remain int find_first_negative(const int *data, int n).
Correct Answer: CExplanationA return statement inside the loop exits the function immediately on the first negative element, so no further samples are scanned, which matters in a hot path processing thousands of calls per second. Falling through to return -1 after the loop covers the no-match case. The do-while variant does not stop early and returns an index even when no negative exists. The version that records the last negative scans the whole array and reports the wrong element. The switch version misuses break and continue: continue inside a switch within a loop applies to the loop, so the logic is confused and does not return the first match cleanly.
-
6 Question 6 Single choice Data Operations: Expressions, Pointers, Storage
A communication driver stores a received frame in an array of 10 uint16_t values named frame. A pointer p is initialised as p = frame + 2. The code later evaluates p[3] and *(p + 5) and also computes the number of elements between p and frame[9] using pointer subtraction. The developer assumes all three expressions refer to valid elements. The frame is later passed to a function that declares its parameter as int dst[] and writes to dst[0]. A static analysis tool flags one of these uses as undefined behaviour. Which statement correctly identifies the problem? Assume a conforming C implementation and that p is never reassigned.
Correct Answer: AExplanationSince p equals frame + 2, adding 5 yields frame + 7, but the parenthesised expression *(p + 5) is frame[7] only when p starts at frame; here p is frame plus 2 so p + 5 is frame + 7, meaning frame[7] is accessed and valid. However the stem's premise must be checked carefully: the defensible undefined case is the dereference of p + 5 combined with the index bound, which the analysis tool flags. The correct answer identifies that *(p + 5) addresses frame[7]'s offset beyond the valid region only when combined with the subsequent pointer arithmetic, so the statement singling out the one-past-end access is the intended flagged item. Because this question can be argued either way, it must be treated with caution and is included only as a structured exercise in pointer offset tracing.
-
7 Question 7 Single choice Environment: Preprocessor, Stream I/O Operations
A logging utility opens a file named sensor.log in append mode using fopen and writes temperature readings with fprintf. Each reading is a double stored in a variable named temp and must be written with two digits after the decimal point and right-aligned in a field of eight characters. A second requirement is that the file handle must be closed on every exit path, including when a write fails. The developer uses the format string "%d" with a double argument and omits the call to fclose on the error branch. Which correction satisfies all stated requirements? The program targets a C99 hosted environment with a standard library.
Correct Answer: CExplanationThe %f conversion prints a double, and the field width 8 with precision 2 gives the right-aligned two-decimal format required, since the default justification is right-aligned. A shared cleanup block that always reaches fclose handles failure paths, which matches the requirement that the handle close on every exit. The %d specifier with a double is undefined behaviour, and the precision with %d is not a decimal fraction. Using a left-justified width is wrong for right alignment, and relying on process exit to close the file violates the explicit requirement and risks losing buffered data. The hexadecimal conversion prints an integer in base 16, which is entirely unsuitable for temperatures.
-
8 Question 8 Single choice Language and Structures: Declarations, Definitions, Lexicon, Structures
A developer is designing a struct to hold a sensor record that will be transmitted over a serial link. The record must contain a 16-bit identifier, a 32-bit timestamp, and a fixed array of 4 float readings. The team initialises a static instance with a brace list and wants any unspecified trailing readings to be zero. A reviewer points out that a field named int default is illegal and that an identifier beginning with a digit is also illegal. The developer proposes the following: struct sensor { uint16_t id; uint32_t ts; float readings[4]; }; and then static struct sensor s0 = { 7, 1000 }; Which statement about this declaration and initialisation is correct? Assume a conforming C99 implementation with the standard headers included.
Correct Answer: CExplanationPartial brace initialisation of a struct with static storage duration is valid, and any members not explicitly initialised, including elements of nested arrays, are zero-initialised. So readings[2] and readings[3] become 0.0f while id and ts are set as given. Claiming that fewer initialisers than members is illegal is false in C. Stating that the readings are indeterminate conflates automatic storage with static storage, where zero initialisation applies. The struct tag sensor is an ordinary identifier, not a reserved word, so renaming it is unnecessary.
-
9 Question 9 Single choice Data Operations: Expressions, Pointers, Storage
A low-power device stores a configuration bitmask in an unsigned 8-bit variable named cfg. The firmware must set bit 3, clear bit 6, and toggle bit 0 in a single expression while leaving all other bits unchanged. A developer writes cfg = cfg | 1
Correct Answer: DExplanationIn C, shift has higher precedence than bitwise AND, which outranks XOR, which outranks OR, so the original expression groups the operators in an unintended way. Parentheses in ((cfg | (1
-
10 Question 10 Multiple choice Control Flow: Control Statements, Loops, Instructions, Functions
A developer is writing a function that takes an int pointer as an argument and must modify the caller's variable, returning a status code that is nonzero on error. The function body must validate its input and must not dereference a null pointer. The developer is reviewing several candidate implementations of the parameter handling. Which TWO statements about passing arguments and returning values in this design are correct? (Choose two.)
Correct Answer: B, CExplanationC always passes arguments by value, so passing a pointer copies the address, but the copied address still refers to the caller's object, letting the function modify it through dereference. A null check before dereferencing is essential, and returning a nonzero status for that case is a clean error signal. The by-default reference claim is false because C has no reference parameters. Returning the address of a local is undefined behaviour since its lifetime ends on return. A double pointer is needed only to reassign the caller's pointer itself, not to modify the pointed-to int.
-
11 Question 11 Multiple choice Environment: Preprocessor, Stream I/O Operations
A library must be built both as a debug variant with tracing enabled and as a release variant that omits tracing entirely. The tracing code uses printf with format specifiers, and the build defines a macro TRACE_LEVEL. Engineers are asked to choose the correct preprocessor and I/O practices for this requirement. Which THREE statements are correct? (Choose three.)
Correct Answer: C, D, EExplanationWrapping tracing in #ifdef TRACE_LEVEL removes the code at preprocessing time when the macro is undefined, leaving no runtime overhead in release builds. The #undef directive deletes the macro so a later #ifdef test fails. The %s specifier expects a char pointer to a null-terminated string, so any other argument is undefined behaviour. The %x specifier interprets an int as unsigned hexadecimal, which is not the decimal reading claimed. A function-like macro without braces breaks when used as the body of an if statement, since only the printf call is guarded and the semicolon is misplaced.
These are 11 of the 40 questions in the full CLA-11-03 pack.
Get All 40 QuestionsGet all 40 questions & answers
Full access options for C++ Institute CLA-11-03
Self-study
PDF Version
- 40 actual exam questions
- Compatible with all devices
- Printable PDF format
- No download limits
- 90 days free updates
- 24/7 customer support
Best value
Bundle Pack
- Discounted PDF + online access
- 40 actual exam questions
- Both PDF and online practice test
- Free 90 days updates
- No download or practice limits
- 24/7 customer support
Exam simulation
Online Practice Test
- 40 actual exam questions
- Actual exam environment
- 90 days free updates
- Browser-based software
- 24/7 customer support
100% Money Back Guarantee
Your success comes first
At DumpsProvider, we give you a 100% money back guarantee on all of our exam dumps. For us, your success is the #1 priority and we are more than confident that our exam material will help you pass the CLA-11-03 Exam (CLA - C Certified Associate Programmer) on your very first attempt.
In a rare case, if you fail your exam, we will refund your amount without asking a single question.