Array
of strings
An
array of strings is a two-dimensional character array. The size of the first
index (rows) denotes the number of strings and the size of the second index
(columns) denotes the maximum length of each string. Usually, array of strings
are declared in such a way to accommodate the null character at the end of each
string. For example, the 2-D array has the declaration:
char Name[6][10];
In
the above declaration, the 2-D array has two indices which refer to the row
size and column size, that is 6 refers to the number of rows and 10 refers to
the number of columns.
For example
char Name[6][10] = {"Mr. Bean", "Mr.Bush",
"Nicole", "Kidman", "Arnold", "Jodie"};
In
the above example, the 2-D array is initialized with 6 strings, where each
string is a maximum of 9 characters long, since the last character is null.
The
memory arrangement of a 2-D array is shown below and all the strings are stored
in continuous locations.
#include<iostream>
using namespace std;
int main( )
{
// initialize 2d
array
char colour
[4][10]={"Blue","Red","Orange", "yellow"};
// printing strings
stored in 2d array
for (int i=0; i
<4; i++)
cout << colour
[i] << "\n";
}
Blue
Red
Orange
Yellow
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.