New Year Sale 2026! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPA-21-02 Exam - Topic 1 Question 17 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 17
Topic #: 1
[All CPA-21-02 Questions]

What happens when you attempt to compile and run the following code?

#include

using namespace std;

void set(struct person*);

struct person

{

char name[25];

int age;

};

int main()

{

struct person e = {"Steve", 30};

set(&e);

cout<< e.name << " " << e.age;

return 0;

}

void set(struct person *p)

{

p?>age = p?>age + 1;

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

0/2000 characters
Judy
3 months ago
I'm surprised this even compiles at all!
upvoted 0 times
...
Katlyn
4 months ago
Wait, is `struct person` even defined before it's used?
upvoted 0 times
...
Katie
4 months ago
I think it should print "Steve 31" if the code was correct.
upvoted 0 times
...
Delbert
4 months ago
Totally agree, that `p?>age` is wrong!
upvoted 0 times
...
Alberto
4 months ago
Looks like a syntax error with the pointer syntax.
upvoted 0 times
...
Shawnee
5 months ago
I’m a bit confused; I thought the struct was defined correctly, but maybe there's an issue with the function prototype?
upvoted 0 times
...
Dorcas
5 months ago
I’m leaning towards option C because it seems like it should print "Steve 31" after incrementing the age.
upvoted 0 times
...
Darell
5 months ago
I remember practicing something similar, but I feel like there's a mistake with how the age is being accessed.
upvoted 0 times
...
Malissa
5 months ago
I think the code should compile, but I'm not sure about the pointer syntax in the set function.
upvoted 0 times
...
Ryann
5 months ago
I'm not sure about this one. The pointer usage in the `set()` function looks a bit tricky. I'll need to review my notes on pointers before attempting to answer.
upvoted 0 times
...
Kris
5 months ago
I think I've got it! The code should print "Steve 31" because the `set()` function increments the `age` field of the `person` object.
upvoted 0 times
...
Franchesca
5 months ago
Hmm, I'm a bit confused about the pointer usage in the `set()` function. I'll need to think through that carefully.
upvoted 0 times
...
Antonio
5 months ago
I'm pretty confident I can solve this. The key is understanding how pointers work in C++.
upvoted 0 times
...
Tran
5 months ago
Okay, let me break this down step-by-step. First, I'll check the structure declaration and how it's used in the `main()` function. Then I'll look at the `set()` function and how it modifies the `person` object.
upvoted 0 times
...
Jeannetta
5 months ago
Optimistic concurrency control is the way to go here. It's lightweight and efficient when conflicts are infrequent, which is the key detail in the question.
upvoted 0 times
...
Pamela
5 months ago
Wait, do they mean load testing will increase budget, or they're concerned about it? I'm a bit confused about the exact scenario here.
upvoted 0 times
...
Dorinda
6 months ago
Okay, I've got this. Time, core competencies, competitive advantage, customer response, and competitor response - those are all key factors to consider when assessing the feasibility of a strategy. I'm confident I can get this one right.
upvoted 0 times
...
Han
10 months ago
Wait, is this a trick question? I feel like I'm missing something obvious. I'm just gonna go with C and hope for the best. Pointers, man... they're like the Rubik's Cube of programming.
upvoted 0 times
Cherrie
9 months ago
C) It prints: Steve 31
upvoted 0 times
...
Chi
9 months ago
B) Error: in structure
upvoted 0 times
...
Elbert
9 months ago
A) Error: in prototype declaration unknown struct person
upvoted 0 times
...
...
Jannette
10 months ago
A classic pointer question! I bet the compiler is gonna scream at me for that weird-looking p->age syntax. I'm feeling confident and going with C, 'Steve 31'.
upvoted 0 times
Shawnda
9 months ago
User 3
upvoted 0 times
...
Kenneth
9 months ago
User 2
upvoted 0 times
...
Donte
10 months ago
User 1
upvoted 0 times
...
...
Ling
10 months ago
Haha, this reminds me of that time I spent hours debugging a pointer issue. Rookie mistake, I know. I'm going to go with C on this one, just to play it safe.
upvoted 0 times
Sabrina
9 months ago
I agree, C seems like the most likely outcome. It's always good to play it safe with these things.
upvoted 0 times
...
Anglea
9 months ago
Yeah, pointers can be tricky. C does seem like the safest option in this case.
upvoted 0 times
...
Bettina
10 months ago
I've made my fair share of pointer mistakes too. It happens to the best of us. C sounds like the safe bet here.
upvoted 0 times
...
...
Lisha
11 months ago
Hmm, I'm leaning towards B. Something seems off with the structure declaration. Maybe it's missing a semicolon or something. I'll have to double-check the syntax.
upvoted 0 times
Shawnda
9 months ago
Definitely A, the error is in the prototype declaration.
upvoted 0 times
...
Kizzy
10 months ago
Yeah, A makes sense. The struct person needs to be defined before it's used in the function.
upvoted 0 times
...
Danica
10 months ago
I agree, it looks like a prototype error. So, A is the correct answer.
upvoted 0 times
...
Dannie
10 months ago
I think it's A. The struct person is not defined before it's used.
upvoted 0 times
...
...
Tasia
11 months ago
Oh wow, this looks like a tricky one! I'm going to guess C, it prints 'Steve 31'. That pointer stuff is always a bit confusing, but I think the set function is modifying the age field directly.
upvoted 0 times
King
10 months ago
I agree, C seems like the correct answer. The set function is probably updating the age field directly.
upvoted 0 times
...
King
10 months ago
I think you're right, it should print 'Steve 31'. That pointer stuff can be tricky to understand.
upvoted 0 times
...
...
Micaela
11 months ago
But the code is trying to access a struct person before it's defined, so I still think it's A).
upvoted 0 times
...
Leota
11 months ago
I disagree, I believe the correct answer is C) It prints: Steve 31.
upvoted 0 times
...
Micaela
11 months ago
I think the answer is A) Error: in prototype declaration unknown struct person.
upvoted 0 times
...

Save Cancel