C Programming (Turbo C++ Compiler) - String array initialization and counting the number of elements
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.
Source Code
#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
|