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 Exam CPA-21-02 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:

Han
22 days 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
Elbert
3 days ago
A) Error: in prototype declaration unknown struct person
upvoted 0 times
...
...
Jannette
1 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
Kenneth
2 days ago
User 2
upvoted 0 times
...
Donte
8 days ago
User 1
upvoted 0 times
...
...
Ling
1 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
Anglea
3 days ago
Yeah, pointers can be tricky. C does seem like the safest option in this case.
upvoted 0 times
...
Bettina
9 days 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
1 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
2 days ago
Definitely A, the error is in the prototype declaration.
upvoted 0 times
...
Kizzy
20 days ago
Yeah, A makes sense. The struct person needs to be defined before it's used in the function.
upvoted 0 times
...
Danica
23 days ago
I agree, it looks like a prototype error. So, A is the correct answer.
upvoted 0 times
...
Dannie
29 days ago
I think it's A. The struct person is not defined before it's used.
upvoted 0 times
...
...
Tasia
2 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
1 months ago
I agree, C seems like the correct answer. The set function is probably updating the age field directly.
upvoted 0 times
...
King
1 months ago
I think you're right, it should print 'Steve 31'. That pointer stuff can be tricky to understand.
upvoted 0 times
...
...
Micaela
2 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
2 months ago
I disagree, I believe the correct answer is C) It prints: Steve 31.
upvoted 0 times
...
Micaela
2 months ago
I think the answer is A) Error: in prototype declaration unknown struct person.
upvoted 0 times
...

Save Cancel