Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CLA-11-03 Exam - Topic 3 Question 6 Discussion

Posted by Novella on Sep 26, 2026 at 10:49 PM

What happens when you compile and run the following program?

#include

int fun (void) {

static int i = 1;

i += 2;

return i;

}

int main (void) {

int k, 1;

k = fun ();

1 = fun () ;

printf ("%d", 1 - k);

return 0;

}

Choose the right answer:

Suggested Answer: A

The provided program has a few key points to consider:

1. fun is a function that uses a static variable i. This means i retains its value between function calls. It's initialized to 1 and then incremented by 2 each time fun is called.

2. The main function calls fun twice, assigning the results to k and l (though there's a typo in the variable name l, it should be l = fun();, not 1 = fun();).

Let's step through the code:

* First call to fun: i starts at 1, increments by 2, so i becomes 3. This value (3) is as-signed to k.

* Second call to fun: i is now 3, increments by 2 again, so i becomes 5. This value (5) is assigned to l.

Finally, the printf statement attempts to print l - k, which is 5 - 3, resulting in 2.

So, the correct answer is:

A . The program outputs 2.


Get Premium CLA-11-03 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
4 comments · newest first
NI
Nieves 3 days ago
I'm not sure about the output, but I think it might be 3 since `i` starts at 1 and increases by 2 each time. So, it should be 1 + 2 + 2, right?
AR
Aretha 8 days ago
I practiced a similar question where static variables were involved, and I think the output will be based on the final value of `i` after two calls to `fun()`.
AU
Audry 13 days ago
Wait, did I read that correctly? The variable `1` in `int k, 1;` seems like a typo. Can we even use numbers as variable names?
RO
Roslyn 18 days ago
I remember that static variables retain their value between function calls, so I think `i` will keep increasing.
0/2000 characters

Save Cancel