The given array
is an array of strings
. Each index of words
is a string.
e.g:
words[0] = "india"
words[1] = "pakistan"
and so on.
You can use words[0][j]
to refer to the characters present in india
, words[1][j]
for referring to characters of pakistan
.
Maybe the following code will help you visualize the array:
#include <iostream>
int main() {
int MAXLENGTH = 10;
char words[][MAXLENGTH] =
{
"india",
"pakistan",
"nepal",
"malaysia",
"philippines",
"australia",
"iran",
"ethiopia",
"oman",
"indonesia"
};
for(int i=0;i<MAXLENGTH;i++)
{
std::string s = words[i];
for(int j=0;j<s.size();j++)
{
std::cout << words[i][j] << " ";
}
std::cout << "\n";
}
return 0;
}
4
solved How does this code initialize the 2D array? [closed]