Question: 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: 0x7ff eebc40a48
 I want you to create a simple program that defines a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!