正在加载图片...
Assignment #10:Pointers (Due:Nov.31) Solve each of the following problems and turn your answer in on paper.You should work these problems through by hand.You should not use VC(nor any C compiler) to obtain answers to any of the problems in Part A of this assignment. Problem 1:Memory diagrams For each of the following programs,draw a diagram showing the structure of memory at the indicated points.In creating your diagrams,you should observe the following conventions: Your diagram must make clear whether each memory block is allocated on the stack of the heap by dividing the diagram into two regions,as illustrated in the example below. Whenever a memory location has been assigned a value,you should show the value; uninitialized memory locations should be left blank. ● You need not show memory that is allocated during the program but is later made inaccessible because all pointers to that data are lost. ● Remember to show the value of all variables that are currently active at each checkpoint. For example,if the program is int main() int *p,*q,r[3]; p=r; q new int[4]; *p+=17; //Draw a diagram indicating the contents of memory at this point. } your diagram should look like that shown bellow: Stack Heap 17 These examples are intentionally written in a cryptic fashion to make sure that you understand the details of pointer manipulation.When you write code of your own,it should not look like these examples.Note also that problem 1b requires you to draw four separate diagrams of memory at each of the four checkpoints.Assignment #10: Pointers (Due:Nov. 31) Solve each of the following problems and turn your answer in on paper. You should work these problems through by hand. You should not use VC (nor any C compiler) to obtain answers to any of the problems in Part A of this assignment. Problem 1: Memory diagrams For each of the following programs, draw a diagram showing the structure of memory at the indicated points. In creating your diagrams, you should observe the following conventions: z Your diagram must make clear whether each memory block is allocated on the stack of the heap by dividing the diagram into two regions, as illustrated in the example below. z Whenever a memory location has been assigned a value, you should show the value; uninitialized memory locations should be left blank. z You need not show memory that is allocated during the program but is later made inaccessible because all pointers to that data are lost. z Remember to show the value of all variables that are currently active at each checkpoint. For example, if the program is int main() { int *p, *q, r[3]; p = r; q = new int[4]; *p++ = 17; // Draw a diagram indicating the contents of memory at this point. } your diagram should look like that shown bellow: These examples are intentionally written in a cryptic fashion to make sure that you understand the details of pointer manipulation. When you write code of your own, it should not look like these examples. Note also that problem 1b requires you to draw four separate diagrams of memory at each of the four checkpoints
向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有