Review Questions

1:What will this program print?
#include <stdio.h>
int main(void)
{
  int ref[] = {8, 4, 0, 2};
  int *ptr;
  int index;

  for (index = 0, ptr = ref; index < 4; index++, ptr++)
     printf("%d %d\n", ref[index], *ptr);
  return 0;
}
2:In question 1, how many elements does ref have?
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 ...

Get C Primer Plus, Fourth 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.