An array of strings can be created using a single-dimension pointer array of type char. - C String

C examples for String:String Array

Description

An array of strings can be created using a single-dimension pointer array of type char.

Demo Code

#include <stdio.h>  
int main()//from  w ww. j a va 2 s  . c  om
{ 
   char *strNames[5] = {0}; 
   char answer[80] = {0}; 
   int x; 
   strNames[0] = "this is a test"; 
   strNames[1] = "this is a test2"; 
   strNames[2] = "this is a test3"; 
   strNames[3] = "this is a test4"; 
   strNames[4] = "this is a test5"; 
   printf("\nNames in pointer array of type char:\n\n"); 
   for ( x = 0; x < 5; x++ ) 
      printf("%s\n", strNames[x]); 
}

Result


Related Tutorials