Software & Finance - Monthly Magazine Online

Volume 4 - Issue 4

April 2014




String Arrays in C++

The source code explains on how to initialize the string arry and count the number of elements. Note that there is no string data type in C and we use char [] as string.

 

#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include <bios.h>

#include <ctype.h>

 

 

static char *arrayCountryNames[] = {

      "USA", "UK", "India", "Dubai", "Singapore", "Australia",

      "Malaysia", "Phillipines", "Manila", "Ethopia", "Canada"

};

 

void main()

{

      int numElements = sizeof(arrayCountryNames) / sizeof(arrayCountryNames[0]);

    int i = 0;

      for(i = 0; i <numElements; i++)

            printf("%s\n", arrayCountryNames[i]);

}

 

OUTPUT

 

USA
UK
India
Dubai
Singapore
Australia 
Malaysia
Phillipines
Manila
Ethopia
Canada