Tutorials

C Pointers


Array of Pointers


In this chapter of this C tutorial, we will learn about 'array of pointers'.

 

Syntax

data-type *array-name[expression];

Where,
expression - is the number of elements to be taken in the array.

  • The square bracket over here will take the precedence over the '*' operator.
  • Each element in array-name will hold a pointer to the data-type.

Example

#include <stdio.h>
void main () 
{
    char *names[5] = 
    {
         "Nikhil",
         "Muskaan",
         "Suraj",
         "Aarti",
         "usman"
    };
    int i;
    for ( i = 0; i < 5; i++) 
    {
         printf("Value of names[%d] = %s\n", i, names[i] );
    }
}

OUTPUT

Value of names[0] = Nikhil
Value of names[1] = Muskaan
Value of names[2] = Suraj
Value of names[3] = Aarti
Value of names[4] = Usman



Please Share this page
Views : 32
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!