Question: 2. (40 points) You need to understand array, pointer and pointer arithmetic to complete this exercise. And you should be able to figure out the

2. (40 points) You need to understand array, pointer and pointer arithmetic to complete this exercise. And you should be able to figure out the answers without actually compiling and running the program.

#include

int main(int argc, char *argv[])

{

char a, *pc, c[8];

int i, *pk, k[8];

a='N';

pc=&(c[7]);

pk=&(k[0]);

for (i=0; i<8; i++)

{

*pc=a-(char)i;

pc--;

*pk=i+5;

pk++;

}

return 0;

}//end of main

Write out the memory map for the above C code in the following table. For array variables, list the address range for the entire array. Assume the memory address starts from 100, that is, the address for a is 100. Suppose sizeof(char)=1, sizeof(int)=4 and the size of a memory address (a pointer) is 8 bytes. You may assume there is no gap in memory between the variables. (18 points)

Variable

Start address

End address

a

pc

c

i

pk

k

Additionally, show values of the variables in the following table at the end of execution of the for loop before the main function returns. (For the two array variables c and k, list the contents of all array elements.) (18 points)

Variable

Value

a

pc

Use an expression involving c to represent pcs value

c

i

pk

Use an expression involving k to represent pks value

k

How many bytes in total does the code allocate for the variables? (4 points)

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!