Note: part b ( id initialized) Problem 2 (8 points): memory picture Consider the
ID: 3753497 • Letter: N
Question
Note: part b ( id initialized) Problem 2 (8 points): memory picture Consider the following struct definition. typedef struct profile( char first initial: double gpa: int id; char code; profile: Consider the code. profile mark 'M, 3.65, NULL, NULL) // picture drawn for you profile ptr&mark: /I update picture ptr->code & (mark.first initial) // update picture A. (5 pts) Update the drawing to show the memory layout after the code snippet executes. Use arrows to indicate the pointers (arrow head should point to the value stored at the memory address of the pointer). If a value is re-assigned, just cross it out and replace it with a new value. mark M' 3.65 NULL NULL ptr B. (3 pts) Suppose the following code is added to the bottom of the code snippet above and the code compiles: printf("Value of id: %d ", * (mark.id)); What is printed when the program runs (hint: is id initialized?)?Explanation / Answer
2 B) The program will show runtime error, with comment "Segmentation fault (core dumped)".
- Getting this error means your program has attempted to access an area of memory that it is not allowed to access
One of common reasons why we can get this error is: if we fail to initialize a pointer before accessing it
-> Since mark.id has not been initialized, we get this error.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.