Answered step by step
Verified Expert Solution
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 heapfreestore 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.
egamember
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.
eg amember
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: ffeebc
Hermione Granger:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started