O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required