Sams Teach Yourself C in 21 Days

(singke) #1
Answers 851

F



  1. The following is one of many possible answers:
    #include <stdio.h>
    / Declare a single-dimensional array /


int elements[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int new_array[10];
int idx;
int main( void )
{
for (idx = 0; idx < 10; idx++)
{
new_array[idx] = elements[idx] + 10 ;
}
for (idx = 0; idx < 10; idx++)
{
printf( “\nelements[%d] = %d \tnew_array[%d] = %d”,
idx, elements[idx], idx, new_array[idx] );
}
return 0;
}

Answers for Day 9

Quiz


  1. The address-of operator is the &sign.

  2. The indirection operator is used. When you precede the name of a pointer by ,it
    refers to the variable pointed to.

  3. A pointer is a variable that contains the address of another variable.

  4. Indirection is the act of accessing the contents of a variable by using a pointer to
    the variable.

  5. They are stored in sequential memory locations, with lower array elements at lower
    addresses.
    6.&data[0]
    data

  6. One way is to pass the length of the array as a parameter to the function. The sec-
    ond way is to have a special value in the array, such as NULL, signify the array’s
    end.

  7. Assignment, indirection, address-of, incrementing, differencing, and comparison.


49 448201x-APP F 8/13/02 11:22 AM Page 851

Free download pdf