Limited-Time Offer: Enjoy 50% Savings! Ends in 00h 00m 00s Coupon code: 50OFF
Skip to content

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

Page: 1 / 7 Total 40 questions

Want more questions? Get Premium Access.

Question 1

What happens if you try to compile and run this program?

enum { A, B, C, D, E, F };

#include

int main (int argc, char *argv[]) {

printf ("%d", B + D + F);

return 0;

}

Choose the right answer:

Correct Answer: E. The progham outputs 9
Explanation:

The program outputs 9 because the expression B + D + F evaluates to 9 using the enumeration constants defined by the enum keyword. The enum keyword creates a user-defined data type that can have one of a set of named values. By default, the first value is assigned 0, and each subsequent val-ue is assigned one more than the previous one, unless explicitly specified. Therefore, in this pro-gram, A is 0, B is 1, C is 2, D is 3, E is 4, and F is 5. The printf function then prints the sum of B, D, and F, which is 1 + 3 + 5 = 9, as a decimal integer using the %d format specifier.

Reference = CLA -- C Certified Associate Programmer Certification, [C Essentials 2 - (Intermediate)], C Enumeration


Question 2

What happens if you try to compile and run this program?

#include

#include

int main (int argc, char *argv[]) {

int a = 0, b = 1, c;

c = a++ && b++;

printf("%d",b);

return 0;

}

Choose the right answer:

Correct Answer: B. The program outputs 1
Explanation:

he expression a++ && b++ involves the logical AND (&&) operator. In C, the logical AND op-erator short-circuits, meaning that if the left operand (a++ in this case) is false, the right operand (b++) is not evaluated.

Initially, a is 0, and b is 1. The result of a++ is 0 (false), so b++ is not evaluated. The value of b remains 1. The printf statement then prints the value of b, which is 1.

Therefore, the correct answer is 'The program outputs 1.'

Reference = CLA -- C Associate Programmer documents


Question 3

What is the meaning of the following declaration?

float ** p;

Choose the right answer:

Correct Answer: D. p is a pointer to a pointer to a float
Explanation:

The declaration float **p; means that p is a pointer to a pointer to a float. It is used to declare a pointer that can point to another pointer, and that pointer, in turn, can point to a float.


Question 4

What happens if you try to compile and run this program?

#include

int main (int argc, char *argv[]) {

char *s = "\\\"\\\\";

printf ("[%c]", s [1]);

return 0;

}

Choose the right answer:

Correct Answer: A. Execution fails
Explanation:

In the program, the character array char *s = '\\\'\\\\'; is defined with the value '\'\\'. When printing s[1] using printf('[%c]', s[1]);, it prints the character at index 1 of the string.

Here's the breakdown of the string \\\'\\\\:

* s[0] is '\'

* s[1] is '''

So, the program outputs [']. Therefore, the correct answer is B. The program outputs [']


Question 5

What happens if you try to compile and run this program?

#include

int main (int argc, char *argv[]) {

int i = 1;

for( ;; i/=2)

if(i)

break ;

printf("%d",i);

return 0;

}

Choose the right answer:

The program executes an infinite loop

Correct Answer: A. The program outputs 1
Explanation:

The program outputs 1 because the for loop terminates when i becomes 0. The for loop has no initialization, condition, or increment expressions, so it will run indefinitely unless a break statement is executed. The loop body consists of a single if statement that checks if i is non-zero, and if so, breaks out of the loop. Otherwise, i is divided by 2 and assigned back to itself. Since i is an integer, the division will truncate any fractional part. Therefore, the loop will iterate until i becomes 0, which will happen after one iteration, as 1 / 2 = 0. The printf function then prints the value of i as a deci-mal integer using the %d format specifier.

Reference = CLA -- C Certified Associate Programmer Certification, [C Essentials 2 - (Intermediate)], C For Loop, C If...Else Statement


Question 6

What happens if you try to compile and run this program?

#define ALPHA 0

#define BETA ALPHA-1

#define GAMMA 1

#define dELTA ALPHA-BETA-GAMMA

#include

int main(int argc, char *argv[]) {

printf ("%d", DELTA);

return 0;

Choose the right answer:

Correct Answer: D. Compilation fails
Explanation:

Let's analyze the macros and the program:

1. ALPHA is defined as 0.

2. BETA is defined as ALPHA - 1, which is 0 - 1.

3. GAMMA is defined as 1.

4. DELTA is defined as ALPHA - BETA - GAMMA. With the previous definitions, this expands to 0 - (0 - 1) - 1.

Now, let's expand DELTA with the given values:

makefileCopy code

DELTA = 0 - (0 - 1) - 1 DELTA = 0 - 0 + 1 - 1 DELTA = 0 + 1 - 1 DELTA = 1 - 1 DELTA = 0

It is important to note that the macro dELTA is defined with a lowercase 'd', but the printf function is trying to print DELTA with an uppercase 'D'. Preprocessor tokens are case-sensitive, so this is a mismatch. However, for the sake of the question, let's assume that dELTA was meant to be DELTA with an uppercase 'D'.

Since the actual calculation results in 0, but there is a typo in the printf statement (it should print dELTA, not DELTA), the compilation will fail due to DELTA not being defined.