Reputation: 141
So I was wondering if there is a way to define each element of a 2-D array similar to how you would define elements of a one dimensional array:
int Array[3] = {2, 3, 4, 5};
If I had a two-dimensional array like:
int Array[3][3]
Is there a way to manually enter the values of the elements like I did above with the single array? I am aware that this is would not be the most effective method, but I need to try it this way to test a small amount of values to make sure my program is working properly.
Thank you!
Upvotes: 1
Views: 50
Reputation: 736
It's very simple dear. It goes like this :-
int a[][3] { {1,2,3}, {4,5,6} };
This creates a 2 X 3
2D array. In multidimensional arrays
you needn't mention the dimension in the first []
but it's compulsory to mention the same in the rest. For ex this is wrong :-
int a[3][] = // whatever ;
So there you go !!
Upvotes: 3