Sunteți pe pagina 1din 3

CIT

231 Name: Fall 2013 Homework Chapter 12 Due 4:30pm, September 17, 2013 1. (5 points) The following declarations are an attempt to access the array data using subscripts that start at one. Will it work? Why or why not? int actual_data[20]; int *data = actual_data 1;

2. (5 points) Arrays in C are stored in row-major order. When is this information relevant?

3. (20 points) Given the declarations and data shown below, evaluate each of the expressions and state its value. Evaluate each expression with the original data shown (that is, the results of one expression do not affect the following one). Assume that the ints array begins at location 100 and that integers and pointers both occupy four bytes of memory. int ints[20] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 100, 120, 130, 140, 150, 160, 170, 180, 190, 200 }; int *ip = ints + 3; Expression ints ints[4] ints + 4 *ints + 4 *(ints + 4) ints[-2] &ints &ints[4] &ints + 4 &ints[-2] 4. (7 points) Given the declaration: int array[4][2]; Give the value of each of the following expressions. Assume that the array begins at location 1000 and that integers occupy two bytes of memory. Expression array array + 2 array[3] array[2] - 1 &array[1][2] &array[2][0] &ints[-2] Value Value Expression ip ip[4] ip + 4 *ip + 4 *(ip + 4) ip[-2] &ip &ip[4] &ip + 4 &ip[-2] Value

5. (6 points) What is the difference (if any) between the variables array1 and array2 in this function? void function( int array1[10] ) { int array2[10]; }

6. (7 points) Match the declaration with its description: 1. int x 2. int x[] 3. int *x 4. int *x[] 5. int *x[][] 6. int **x 7. int (*x)[] A. B. C. D. E. F. G. H. declare x as a pointer to array of int declare x as an array of pointers to int declare x as an array of int declare x as int declare x as a pointer to pointer to int declare x as a pointer to int declare x as array of array of pointer to int declare x as function returning pointer to int

S-ar putea să vă placă și