正在加载图片...
-8- Problem 6-Pointer tracing(10 points) Evaluate the following program by hand and show what output it produces: /* File:ptrtrace.c This file does nothing useful and exists only to test your understanding of pointers. */ #include <stdio.h> #include <string.h> #include "genlib.h" #include "strlib.h" /Private function prototypes static void Bizarre(int *pl,int *p2,int n); static int *Weird(int array[],int n); static void Checkpoint(int ckpt,int array[],int n); /Statically initialized arrays * static int a1[]={10,11,12,13,14}: static int a2[]={3,4,0,1,2}; /Main program main ( int i,*p; Checkpoint(0,al,5); Bizarre(al,a2,5); Checkpoint(1,al,5); p Weird(Weird(a2,2),4); Checkpoint(2,a2,5); static void Bizarre(int *pl,int *p2,int n) int *p3,*array; array p3 GetBlock(n sizeof(int)); while (n-->0){ *p3++=p1[*p2++]; while (p3--!=array)( p1[p3-array】=*p3;– 8 – Problem 6—Pointer tracing (10 points) Evaluate the following program by hand and show what output it produces: /* * File: ptrtrace.c * ---------------- * This file does nothing useful and exists only to test your * understanding of pointers. */ #include <stdio.h> #include <string.h> #include "genlib.h" #include "strlib.h" /* Private function prototypes */ static void Bizarre(int *p1, int *p2, int n); static int *Weird(int array[], int n); static void Checkpoint(int ckpt, int array[], int n); /* Statically initialized arrays */ static int a1[] = { 10, 11, 12, 13, 14 }; static int a2[] = { 3, 4, 0, 1, 2 }; /* Main program */ 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); } static void Bizarre(int *p1, int *p2, int n) { int *p3, *array; array = p3 = GetBlock(n * sizeof(int)); while (n-- > 0) { *p3++ = p1[*p2++]; } while (p3-- != array) { p1[p3 - array] = *p3; } }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有