![]() |
In C++, a 2D array is an array of arrays that stores data in the form of a grid with rows and columns. In this article, we will learn how to create a 2D array of a specific size and fill it with some value in C++. Example Input: rows = 3; columns = 3; value = 1; Output: 2D Array: { {1, 1, 1}, {1, 1, 1}, {1, 1, 1} } Create a 2D Array of a Specific Size and Value in C++We can create a 2D array of the given size by specifying the size of the rows as the first dimension size and the column size as second dimension size as shown below: Syntax to Create 2D ArrayThe syntax for creating and initializing a 2D array in C++ is as follows: datatype array_name[row_size][column_size];
We can then use nested loops to fill the values in a 2D array. C++ Program to Create a 2D Array of a Specific Size and ValueThe below example demonstrates how we can create a two dimensional array and fill it with values in C++. C++
Output 1 1 1 1 1 1 1 1 1 Time Complexity: O(n*m) , here n and m are rows and columns respectively |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |