C - Building an array of pointers

Introduction

An array of pointers is an array that holds memory locations.

An array of pointers is really an array of strings in the following code.

Demo

#include <stdio.h> 

int main() //from  w w w .  j a  va 2 s. co  m
{ 
   char *fruit[] = { 
       "abc", 
       "def", 
       "pear", 
       "apple", 
       "Java", 
       "XML", 
       "CSS" 
   }; 
   int x; 

   for(x=0;x<7;x++) 
       puts(fruit[x]); 

   //replace the array notation with pointer notation. 
   for(x=0;x<7;x++)
       puts(*(fruit+x));
   return(0); 
}

Result

Related Topic