ECE-1011 (SPRING 2003)

QUIZ #8 PREP SHEET

NOTE: This quiz will covers both the material for Quiz #7 and Quiz #8.

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

  1. An array is:
    1. a group of values having a common variable name and all of the same data type.
    2. a collection of elements of different data types that are stored in adjacent memory locations.
    3. a variable that contains multiple values of different data types.
    4. 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 the following code fragment 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 variance a measure of?
  13. In the function call:

    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?

     

  15. A pointer variable
    1. contains the data stored at a location in memory.
    2. contains the address of a memory location.
    3. can be used in input statements, but not output statements.
    4. can be changed to different values in both input and output statements.
  16. How would you assign to the variable name the value of a variable referenced by the pointer a?
    1. a = &name;
    2. name = &a;
    3. a = *name;
    4. name = *a;

     

  17. What is the advantage of using pointers in functions?

     

  18. What are the potential problems if a pointer is not initialized before use? If a pointer is originally unused what should the pointer be initialized to?

     

  19. A function prototype is given as:

void switch(int *a, int *b);

If x and y are defined as integers how should the switch function be called in main so that the values of x and y are passed into the function correctly?