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:

Lisha
21 hours 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
...
Tasia
8 days 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
...
Micaela
14 days 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
21 days ago
I disagree, I believe the correct answer is C) It prints: Steve 31.
upvoted 0 times
...
Micaela
23 days ago
I think the answer is A) Error: in prototype declaration unknown struct person.
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77