Search
 
SCRIPT & CODE EXAMPLE
 

CPP

2-Dimensional array in c++

int row,col;
cout << "please input how many rows and columns you want accordingly: ";
cin>>row>>col;
//create array in heap.
int **arr=new int*[row];
for(int i=0;i<row;i++)
{
    arr[i]=new int[col];
}
//getting value from user.
for(int i=0;i<row;i++)
{
    for(int j=0;j<col;j++)
    {
        cout<<"Enter a number ";
        cin>>arr[i][j];
    }
}
//display Elements.
    for(int i=0;i<row;i++)
{
    for(int j=0;j<col;j++)
    {
        cout<<arr[i][j]<<" ";
    }
}

return 0;
Comment

2d array c++

int a[2][3]= {
        {1, 2, 3},
        {4, 5, 6}
    };
    
    cout << a[1][1]; // Output is 5
Comment

2d array c++

//* 2D arrays
int n, m;
cout << "Enter row and column: ";
cin >> n >> m;
int arr[n][m];
for (int i = 0; i < n; i++)
{
  for (int j = 0; j < m; j++)
  {
    cin >> arr[i][j];
  }
}

cout << "
Showing array
";

for (int i = 0; i < n; i++)
{
  for (int j = 0; j < m; j++)
  {
    cout << arr[i][j] << " ";
  }
  cout << endl;
}
Comment

C++ Multi-Dimensional Arrays

string letters[2][4] = {
  { "A", "B", "C", "D" },
  { "E", "F", "G", "H" }
};
Comment

PREVIOUS NEXT
Code Example
Cpp :: std distance 
Cpp :: c++ structure 
Cpp :: c++ splitstring example 
Cpp :: c++ int 
Cpp :: debugging c/c++ with visual studio code 
Cpp :: Count Prefix of a Given String solution leetcode 
Cpp :: how to dynamically allocate an array c++ 
Cpp :: what is c++ standard library 
Cpp :: int max c++ 
Cpp :: c++ add two matrix 
Cpp :: int main() { 
Cpp :: print octal number in c++ 
Cpp :: for loop f# 
Cpp :: reverse order binary tree in c++ 
Cpp :: insert a character into a string c++ 
Cpp :: reverse function in cpp array 
Cpp :: image shapes in opencv c++ 
Cpp :: new float array c++ 
Cpp :: c++ cout without include iostream 
Cpp :: classes constructor in c++ 
Cpp :: descending order c++ 
Cpp :: array length c++ 
Cpp :: c++ doubly linked list 
Cpp :: c++ #include 
Cpp :: vector of vectors of pairs c++ 
Cpp :: visual studio getline not working 
Cpp :: how to reverse a vector in c++ 
Cpp :: looping in map c++ 
Cpp :: c++ fonksion pointer 
Cpp :: use of strstr in c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =