3 Arrays
3 Arrays
// take input from the user and store the value at third position
cin >> mark[2];
• Array initialization:
int x[3][3]={{1,2,3},{2,3,4},{3,4,5}};
• Accessing Elements of Two-Dimensional Arrays: Elements in Two-
Dimensional arrays are accessed using the row indexes and column indexes.
Example:
x[2][1];
// C++ Program to display all elements of an initialize two dimensional array
#include <iostream>
using namespace std;
int main()
{ test[0][0] = 2
test[0][1] = -5
int test[3][2] = {{2, -5}, {4, 0}, {9, 1}}; test[1][0] = 4
for (int i = 0; i < 3; ++i) // use of nested for loop access rows of the array test[1][1] = 0
test[2][0] = 9
{ test[2][1] = 1
int main()
{
char str[100];
cout << "Enter a string: ";
cin >> str;
cout << "You entered: " << str << endl;
cout << "\nEnter another string: ";
cin >> str;
cout << "You entered: "<<str<<endl;
return 0;
}