The following few questions are some ideas that my professor said that I should know before class tomorrow. I get really confused with pointers so some help would be great!
1. Assume an array is declared as follows: int myarray[12];. Assuming that int is represented with two bytes, and that array starts in the memory at address 1000, show a memory layout indicating the addresses for this array elements. Let myarray[10] contain the value 0xa0b1. Show the contents of memory at addresses corresponding to the two bytes of myarray[10] for Big-endian convention.
2. In addition to the array above, let us also declare a couple of pointers:
int *pINTARRAY1, *pINTARRAY2; //Line 1
pINTARRAY1 = myarray+4; //Line 2
pINTARRAY2 = &myarray[10]; //Line 3
*pINTARRAY1 = 0x1013; //Line 4
*pINTARRAY2 = 0x1d2e; //Line 5
What is the L-value and R-value of the variables pINTARRAY1 and pINTARRAY2 after Line 3? (If you do not have enough information to answer the question, make assumptions and state them clearly). Which myarray values are written in Lines 4 & 5 and with what values?
3. In Problem 2 above, assuming there is more of a program following it, what can you say about the potential values the pointers pINTARRAY1 and pINTARRAY2 can hold during the program execution? Explain your answer.
4. Given the following program fragment:
unsigned int num_array = {100, 200, 300, 400, 500, 600, 700};
unsigned int *ptr_array;
unsigned int x, y;
ptr_array = num_array;
x = *ptr_array++;
y = *ptr_array++;
What are the values of x, y, ptr_array through this execution? Explain.
5. Compile a program similar to the Problem 1 and 2 above for AVR Atmel Mega128. Declare an array of 12 integers. Declare a pointer to integers. Make it point to the starting address of this array added to a long variable. Should the compiler be able to detect an error for this pointer assignment? Compile it and see if the compiler complains?