19.3k views
3 votes
Consider the code fragment below. Show the values stored at each location in memory and as they change while the code executes. Use the memory addresses given in the comments following each statement. Assume all integer and pointer sizes are four bytes and each box in the memory representation is 4 bytes.

int x; // x is at memory address 5000
int *y; // *y is at memory address 5004
int *z; // *z is at memory address 5008
int *a; // a is at memory address 5012
z=&x;
y=malloc(5 * sizeof(int)); // malloc returns
// address 6000
X = 10;
y[1] = 15;
y[2] = *z; x=*(y + 1);
a = malloc(sizeof(int)); // malloc returns // address 6020
*a = *y; a = z; *z= 25; *a = 12; y[3] = *z; y[4] = x; y[0] = x;

User Kayue
by
7.8k points

1 Answer

3 votes

Answer:

see explaination

Step-by-step explanation:

Final value :-

Memory => value = reference in code

5000 => 12 = x

5004 => 6000 = *y

5008 => 5000 = *z

5012 => 5000 = *a

6000 => 12 = y[0]

6004 => 15 = y[1]

6008 => 10 = y[2]

6012 => 12 = y[3]

6016 => 12 = y[4]

6020 =>

User GabrielP
by
8.7k points