Comp 1572, Winter 2002 Pencil-and-Paper Assignment 5 Assigned Monday, February 11, 2002 Due Monday, February 18, 2002 (At the beginning of class) ============================================================================ This is pencil-and-paper homework. Write your answers as neatly as possible. If your handwriting is hard to read, please type your answers. ============================================================================ 1. Given the following declaration, int a[] = {1,2,3,4,5}; what are the values of the expressions below? (a) a - &a[3] (b) *(a+4) (c) *(a+5) 2. Explain the meaning of each of the following declarations: (a) char a[]; (b) char *b; (c) char c[5] = ""; (d) int d[] = {0,1,2}; (e) int *e = d+1; (f) char *g[]; (g) char *g[] = {a,b,c}; (h) char **a; (i) char **a = &b; (j) typedef int (* C_FN)(char *, const char *); 3. Given that k is an integer array starting at location 2000, kPtr is a pointer to k, and each integer is stored in 4 bytes of memory: (a) What location does kPtr + 5 point to? Refer to the second element of k using; (b) array subscript notation (c) pointer/offset notation with the array name as the pointer (d) pointer subscript notation (e) pointer/offset notation 4. Consider the following function: void func( char * string1, const char * string2 ) { int stringsize = sizeof( string1 )/sizeof( char ); *( string1 + stringsize -1 ) = ‘\0’; string1 = string1 + stringsize - 2; for ( ; *string2 != '\0'; string1--, string2++ ) *string1 = *string2; } Explain in detail what the function func does. Write a main function to test func. Attach the program and its execution result. 5. Provide the definition for each of the following structures. (a) A structure called Address that contains character arrays streetAddress[ 25 ], city[ 20 ], state[ 3 ] and zipCode[ 6 ]. (b) Structure Student that contains arrays firstName[ 15 ] and lastName[ 15 ], integer id, floating-point GPA, and variable homeAddress of type struct Address from part (a). 6. Say that you have the following in your program: int i; int *ip; int **ipp; i = 4000; ip = &i; ipp = &ip; Say that i is stored at memory location 0x606EF0, ip is stored at memory location 0x606EF8 and ipp is stored at memory location 0x606F08. a) Draw a map of the memory and fill in the values of each variable. b) What is the value of each of the following (some are not even logically valid expressions - note which ones are not): i, &i, *i, &ip, ip, *ip, **ip, &*ipp, *ipp, **ipp, &&i, &ipp. 7. Do problem 6.12 in Deitel and Deitel 8. Do problem 16.7 in Deitel and Deitel