Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want you to create a simple program that defines a struct called Friend. The Friend struct should have only one member, a string called

I want you to create a simple program that defines a struct called Friend. The Friend struct should have only one member, a string called name. Then, in the main() function, I want you to dynamically create two Friend structs on the heap/free-store using the new keyword and set the names of both friends. Finally, I would like for you to print to the screen the names of both friends along with their addresses. Not their physical addresses in the world, but the address that their struct is located at in memory. Remember that when trying to access a member using a pointer you have two options, but the first will get you made fun of at work someday. You can dereference the pointer using * then access the member using dot notation, but since the . has a higher order of operations than dereferencing, you have to dereference in parentheses.
e.g.(*a).member
The far more common way is to use the arrow operator -> whenever you have a pointer on the left. It dereferences first then accesses the member all in one operation.
e.g. a->member
While you don't have to delete the structs using the delete keyword since your entire program's memory will be deallocated at the end of main(), it would still be a good idea, just to show that you knew you needed to. Strictly speaking though, I won't grade any points on you remembering to delete the structs that are about to be deleted anyway.
Sample Output
Ron Weasley: 07ffeebc40a50
Hermione Granger:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

Why do most NNOs use fund accounting?

Answered: 1 week ago