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;
}
Suggested Answer: D
Get Premium CPA-21-02 Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
40 comments · newest first
JU
Judy
11 months ago
I'm surprised this even compiles at all!
KA
Katlyn
11 months ago
Wait, is `struct person` even defined before it's used?
KA
Katie
11 months ago
I think it should print "Steve 31" if the code was correct.
DE
Delbert
11 months ago
Totally agree, that `p?>age` is wrong!
AL
Alberto
11 months ago
Looks like a syntax error with the pointer syntax.
SH
Shawnee
12 months ago
I’m a bit confused; I thought the struct was defined correctly, but maybe there's an issue with the function prototype?
DO
Dorcas
12 months ago
I’m leaning towards option C because it seems like it should print "Steve 31" after incrementing the age.
DA
Darell
12 months ago
I remember practicing something similar, but I feel like there's a mistake with how the age is being accessed.
MA
Malissa
1 year ago
I think the code should compile, but I'm not sure about the pointer syntax in the set function.
RY
Ryann
1 year 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.
KR
Kris
1 year 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.
FR
Franchesca
1 year ago
Hmm, I'm a bit confused about the pointer usage in the `set()` function. I'll need to think through that carefully.
AN
Antonio
1 year ago
I'm pretty confident I can solve this. The key is understanding how pointers work in C++.
TR
Tran
1 year 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.
JE
Jeannetta
1 year 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.
PA
Pamela
1 year 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.
DO
Dorinda
1 year 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.
HA
Han
1 year 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.
CH
Cherrie
1 year ago
C) It prints: Steve 31
CH
Chi
1 year ago
B) Error: in structure
EL
Elbert
1 year ago
A) Error: in prototype declaration unknown struct person
JA
Jannette
1 year 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'.
SH
Shawnda
1 year ago
User 3
KE
Kenneth
1 year ago
User 2
DO
Donte
1 year ago
User 1
LI
Ling
1 year 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.
SA
Sabrina
1 year ago
I agree, C seems like the most likely outcome. It's always good to play it safe with these things.
AN
Anglea
1 year ago
Yeah, pointers can be tricky. C does seem like the safest option in this case.
BE
Bettina
1 year 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.
LI
Lisha
1 year 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.
SH
Shawnda
1 year ago
Definitely A, the error is in the prototype declaration.
KI
Kizzy
1 year ago
Yeah, A makes sense. The struct person needs to be defined before it's used in the function.
DA
Danica
1 year ago
I agree, it looks like a prototype error. So, A is the correct answer.
DA
Dannie
1 year ago
I think it's A. The struct person is not defined before it's used.
TA
Tasia
1 year 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.
KI
King
1 year ago
I agree, C seems like the correct answer. The set function is probably updating the age field directly.
KI
King
1 year ago
I think you're right, it should print 'Steve 31'. That pointer stuff can be tricky to understand.
MI
Micaela
2 years ago
But the code is trying to access a struct person before it's defined, so I still think it's A).
LE
Leota
2 years ago
I disagree, I believe the correct answer is C) It prints: Steve 31.
MI
Micaela
2 years ago
I think the answer is A) Error: in prototype declaration unknown struct person.