BLACK FRIDAY SALE – Unlock Up to 25% OFF on All Exam Prep! - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

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

Posted by Beata on Sep 25, 2026 at 04:20 PM

-

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

#include

int *f();

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

int *p;

p = f();

printf("%d",*p);

return 0;

}

int *f() {

static v = 1;

return &v;

}

Choose the right answer:

Suggested Answer: A

The program outputs 1 because the static variable v is initialized to 1 inside the f function, and it is visible to the main function. The f function returns the address of v, which is a pointer to an int. The main function dereferences the pointer and assigns it to p, which is another pointer to an int. Then, the main function prints the value of *p, which is the same as dereferencing p again. Therefore, the output of the program is:

f() = &v p = f() printf(''%d'',*p) = &v = 1

The other options are incorrect because they either do not match the output of the program or do not use the correct concept of static variables.


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
13 comments · newest first
ET
Ettie 2 days ago
Definitely A, no doubt about it!
ME
Mel 7 days ago
Wait, is the static variable even initialized properly?
SU
Sue 12 days ago
I think it compiles fine, so A is correct.
GW
Gwenn 17 days ago
The program outputs 1.
SI
Silva 22 days ago
Yeah, I think it’s definitely 1 too!
PU
Pura 27 days ago
Compilation won't fail, it's valid C code.
IL
Iluminada 1 month ago
Wait, are you sure? What if the static variable isn't initialized?
AN
Antonio 1 month ago
Totally agree, it returns the address of static variable.
RE
Ressie 1 month ago
The program outputs 1.
ME
Melissia 2 months ago
I’m confused about the output. Does the static variable get initialized every time? I thought it would just return the same value.
MO
Mozelle 2 months ago
I practiced a similar question where a function returned a pointer, and it worked fine. I guess it should compile without errors.
AN
Antione 2 months ago
I'm not entirely sure, but I remember something about static variables retaining their value. Could it be option A?
CA
Catalina 2 months ago
I think the function `f()` returns a pointer to a static variable, so it should output 1.
0/2000 characters

Save Cancel