1. Explain what the * and & mean in the following lines of C:

    int i ;
    i = 2 * 2 ;

    char * ptr ;

    ptr = &i ;

    *ptr = 99 ;

  2. What is the difference between *ptr = 100 and ptr [0] = 100

  3. How many characters can the following string array hold?

    char name [20] ;

  4. How many characters worth of memory will the following array take up?

    char board [3] [3] [3] ;













Answers
  1. int i ;
    i = 2 * 2 ;

    In this case we are using * to mean the multiply operator.

    char * ptr ;

    In this case * means that ptr is declared as a pointer to variables of the charactor type

    ptr = &i ;

    In this case, the & means that the compiler is to produce code which will set ptr to point to the memory location where i is stored

    *ptr = 99 ;

    In this case the * means to follow the pointer to the item it points to then use that item. Whatever memory location is pointed to by ptr will be set to the value 99. If ptr points to i, this has the same effect as setting i to 99

  2. There is no difference, Both the subscript and the * will cause the memory location which ptr points to to be set to 100.

  3. It can only hold 19 charactors, as you must make room for the terminating 0 at the end.

  4. This will need 3 * 3 * 3 = 27 memory locations. It is probably for a 3D Naughts and Crosses program.