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 ...

Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.