正在加载图片...
Problem 3-Pointer tracing (10 points) Evaluate the following program by hand and show what output it produces: void Bizarre (int pl[l,int p2[],int n); int *Weird(int array[,int n) int *Weird (int array[],int n); void Checkpoint (int ckpt,int arr[,int n); int *p,i; p=array; int al0={10,11,12,13,14}; for (i=1;i<n;++ inta20={3,4,0,1,2}; { ConsoleT console; if (*p<array[i]) int main() p=array +i; } int i,*p; } Checkpoint(0,al,5); (*p-; Bizarre (al,a2,5); return (p); Checkpoint(1,al,5); p=Weird (Weird (a2,2),4); Checkpoint(2,a2,5); void Checkpoint(int ckpt,int array,int n) void Bizarre(int p10,int p2[,int n) int i; console.printLine ("Checkpoint "ckpt,":{") int *p3,*array; for (i=0;i<n;i++) array p3 new int [nl; { while (n-->0) if (i>0)console.printLine ("") *p3++=pl[*p2++ console.printLine (array[i]); while (p3--!=array) pl[p3-array]=*p3; console.printLine (}\n"); The Checkpoint function does exactly what its comments say it does:display the contents of an array preceded by a checkpoint number.Thus,to answer this problem,all you have to do is show the output at each of the calls to Checkpoint.The results of the first call are filled in as an example. Answer to problem 6: C:\Windows\system32\cmd.exe Checkpoint0:{10,11,12,13,14} Checkpoint0:(10,11,12,13,14) Checkpoint 1: Checkp0int1:(13,14,10,11,12) Checkpoint 2:3.2.0.1.2 Checkpoint 2: Press any key to continue···■Problem 3—Pointer tracing (10 points) Evaluate the following program by hand and show what output it produces: void Bizarre (int p1[], int p2[], int n); int *Weird (int array[], int n); void Checkpoint (int ckpt, int arr[], int n); int a1[] = { 10, 11, 12, 13, 14 }; int a2[] = { 3, 4, 0, 1, 2 }; ConsoleT console; int main() { int i, *p; Checkpoint (0, a1, 5); Bizarre (a1, a2, 5); Checkpoint (1, a1, 5); p = Weird (Weird (a2, 2), 4); Checkpoint (2, a2, 5); } void Bizarre(int p1[], int p2[], int n) { int *p3, *array; array = p3 = new int [n]; while (n--> 0) *p3++ = p1[*p2++]; while (p3--!= array) p1[p3 -array] = *p3; } int *Weird(int array[], int n) { int *p, i; p = array; for (i = 1; i < n; i++) { if (*p < array[i]) { p = array + i; } } (*p)--; return (p); } void Checkpoint(int ckpt, int array[], int n) { int i; console.printLine ("Checkpoint ", ckpt, ": { "); for (i = 0; i < n; i++) { if (i > 0) console.printLine (", "); console.printLine (array[i]); } console.printLine (" }\n"); } The Checkpoint function does exactly what its comments say it does: display the contents of an array preceded by a checkpoint number. Thus, to answer this problem, all you have to do is show the output at each of the calls to Checkpoint. The results of the first call are filled in as an example. Answer to problem 6: Checkpoint 0: { 10, 11, 12, 13, 14 } Checkpoint 1: Checkpoint 2:
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有