Review Questions

I l @ ve RuBoard

Review Questions

  1. What will this program print?

     #include <stdio.h> char ref[] = { 'D', 'O', 'L', 'T'}; int main(void) {   char *ptr;   int index;   for (index = 0, ptr = ref; index < 4; index++, ptr++)      printf("%c %c\n", ref[index], *ptr);   return 0; } 
  2. In Question 1, what storage class is ref ?

  3. In Question 1, ref is the address of what? What about ref + 1 ? What does ++ref point to?

  4. What is the value of *ptr and of *(ptr + 2) in each case?

    1.  int *ptr; int torf[2][2] = {12, 14, 16}; ptr = torf[0]; 
    2.  int * ptr; int fort[2][2] = { {12}, {14,16} }; ptr = fort[0]; 
  5. What is the value of **ptr and of **(ptr + 1) in each case?

    1.  int (*ptr)[2]; int torf[2][2] = {12, 14, 16}; ptr = torf; 
    2.  int (*ptr)[2]; int fort[2][2] = { {12}, {14,16} }; ptr = fort; 
  6. Suppose you have the following declaration:

     int grid[30][100];. 
    1. Express the address of grid[22][56] one way.

    2. Express the address of grid[22][0] two ways.

    3. Express the address of grid[0][0] three ways.

  7. Create an appropriate declaration for each of the following variables :

    1. digits is an array of ten int s.

    2. rates is an array of six float s.

    3. mat is an array of three arrays of five integers.

    4. pstr is a pointer to an array of 20 char s.

    5. psa is an array of 20 pointers to char .

    1. Declare an array of six int s and initialize it to the values 1 , 2 , 4 , 8 , 16 , and 32 .

    2. Use array notation to represent the third element (the one with the value 4 ) of the array in part a.

  8. What is the index range for a ten-element array?

  9. Suppose you have these declarations:

     float rootbeer[10], things[10][5], *pf, value = 2.2; int i = 3; 

    Identify each of the following statements as valid or invalid:

    1. rootbeer[2] = value;

    2. scanf("%f", &rootbeer );

    3. rootbeer = value;

    4. printf("%f", rootbeer);

    5. things[4][4] = rootbeer[3];

    6. things[5] = rootbeer;

    7. pf = value;

    8. pf = rootbeer;

I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net