Answers for "initialize 2d array c++"

C++
1

Initialization of 2D array

int nums[2][3]  =  { {16, 18, 20}, {25, 26, 27} };
Posted by: Guest on June-08-2021
5

declaring 2d dynamic array c++

int** arr = new int*[10]; // Number of Students
int i=0, j;
for (i; i<10; i++) 
	arr[i] = new int[5]; // Number of Courses
/*In line[1], you're creating an array which can store the addresses
  of 10 arrays. In line[4], you're allocating memories for the 
  array addresses you've stored in the array 'arr'. So it comes out 
  to be a 10 x 5 array. */
Posted by: Guest on September-18-2020
5

initialise 2d vector in c++

// Initializing 2D vector "vect" with 
// values 
vector<vector<int> > vect{ { 1, 2, 3 }, 
                           { 4, 5, 6 }, 
                           { 7, 8, 9 } };
Posted by: Guest on May-16-2020
0

how to initialize 2d array with values c++

int main()
{
    int arr[2][5] =
    {
        {1,8,12,20,25},
        {5,9,13,24,26}
    };
}
Posted by: Guest on May-30-2021
0

get elements of 2d array c++

void printMatrix(array<array<int, COLS>, ROWS> matrix){
for (auto row : matrix){
//auto infers that row is of type array<int, COLS>
for (auto element : row){
cout << element << ' ';
}
cout << endl;
}
Posted by: Guest on May-25-2020
-3

initialize 2d array c++

#include <array>
2 #include <iostream>
3
4 using namespace std;
5
6 //remember const!
7 const int ROWS = 2;
8 const int COLS = 3;


int main(){
 array<array<int, COLS>, ROWS> matrix = {
 1, 2, 3,
 4, 5, 6
 };
  
  
  return 0;
}
Posted by: Guest on May-30-2020

Browse Popular Code Answers by Language