ECE-1011 (SPRING 2003)

QUIZ #7 PREP SHEET

 

NOTE: Some of these questions/statements require you to think beyond the strict information given in the text.

 

1)       An array is:

a)       a group of values having a common variable name and all of the same data type.

b)      a collection of elements of different data types that are stored in adjacent memory locations.

c)       a variable that contains multiple values of different data types.

d)      a location in memory that holds multiple values of the same data type.

2)       How is an individual element in an array addressed?

 

3)       The subscript identifies the ________________  of a particular element in the array?

 

4)       What does the following code fragment do?

 

sum = 0;

for(row=0; row<n_rows; row++)

    sum += Table[row][2];

 

5)       Give corresponding snapshots of memory after each of the following sets of code fragments is executed.  Use ? to indicate an array element that is not initialized.

 

int r,c,x[4][5]

...

for(r=0; r<=3; r++)

{

    for(c=0;c<=4; c++)

    {

        x[r][c] = r + c;

    }

}

  

6)       Give the value in sum after the following code fragment is executed:

 

int x[4][4] = {{1,2,3,4},{5,6,7,8},{9,8,7,3},{2,1,7,1}};

...

sum = 0;

for(i=1; i<=3; i++)

{

   for(j=0; j<=3; j++)

   {

         if(x[i][j] > x[i-1][j])

             sum++;

   }

}

  

7)       What does strcmp(s[],t[]) return if:

char s[] = “Hello”;

char t[7] = “HELLO”;

8)       What is the result of the following code fragment?

 

    int x[][3] = {{2,3,1}, {0,-3,5}};

    ...

    return (x[2][2]);

  

9)       What is the value of y[2][3] after the following code fragment has been run?

 

int i,j, n=3;

double y[n][n];

...

for(i=0; i<=n-1; i++)

{

   for(j=0; j<=n-1; j++)

   {

      y[j][i] = n*(j+i);

   }

}

 

 

10)    What is the average and the median of x if:

 

x[9] = {0,1,2,2,6,6,6,7,8};

 

11)    How is standard deviation related to variance?

 

12)    What is deviance a measure of?

 

13)    In the function declaration:

 

double mean( double x[], int n)

 

What value should n contain?

 

14)    Arrays are passed into functions by reference rather than by value.  What does that mean?