Hello and welcome to the goal and programming language course in this session.
We want to talk about the other hottest concepts.
Multidimensional at A.
As we already know, that arrays are one dimensional, but you are allowed to create a multidimensional
array, multidimensional arrays are the arrays of arrays of the same type.
In go language, you can create a multidimensional a using the following syntax.
Indecision, we want to talk about two dimensional array, a two dimensional arrays, in a sense at
least of one dimensional arrays to declare a two dimensional at a right something as follows that.
Add a name Esquire bracket, it's Esquire bracket y and very, very tight.
They're very able Typekit can be any valid go data time and rename will be a valid go identifier.
A two dimensional array can be king as a table, which will have X number of rolls and Y number of colors.
For the example, a two dimensional adi, which contains two rows and three continents, can be shown
as below table.
You can create a multidimensional ADI using via keyboard or using shorthand declaration in multidimensional
at a if a sin is not initialized with some manual by the user, then it will be initialized with zero
by the compiler automatically.
There is no initialized concept in the goal link.
Now go to this good program to illustrate the concept of multidimensional array.
Well, OK, we create an initialized two dimensional arrow using shorthand declaration and that keyboard
declaration first shorthand declaration, right?
The following code for the example Ray one column he calls this group rocket three for the rolls.
And this group, rocket three for the Collins and Type is a strange and Charlie rockets and initialize
the value.
First.
For example, go.
Java
Seashore.
And sits the comma here, comma is necessary in the next line
and other value, for the example, see?
Come on.
Scala, come here and set the comma and in the next line.
Python
C Plus Plus.
And, Ruby,
before that, the court now we define two dimensional at a and initialize it.
Accessing the values of the array using for loop.
So right, the following code first put into mrJ
FP elements at a long go to the next line and use prong for loop.
Create a method for Loop for iterate, the array value first for iterate between rolls and second for
Iterate.
Between this column full on KOLLAN equals zero i less than three because the numbers are always three
and i + +
+ for the columns.
For G Column equal zero j less than three j + +
for loop condition is less than three because column numbers are one two dimensional of at A1 is three.
Now write the value of each set for the example rows zero and column zero.
It returns the value of row zero, column zero cell or row zero and column one returns value of row
zero, column one said.
Now write the code if f person is backslash T and set to add a one here four row set index I and four
column set index J.
After end of each row, we go to the next line by the following command f p reformat the code, save
the project and execute the code.
Now we can see the output, we see that the elements of each row and column are displayed separately
and printed in three rows and three columns, now creating a two dimensional array using via keyboard
and initializing a multi-dimensional array using index.
First, clear the last code
and define a two dimensional variable via every tool set to value for the row in the X and set the tool
value or the column in the X and data type.
Is it in the next line?
The initialize the variable every two
rows zero Collins zero and initialize value 10 the next line array to row zero and column volume set
the value 20.
These are for the first three to row one.
And Column zero initialized by 30 value very two row one column long and initialize it by 14 percent.
The message FP alignments of ready to
go to the next line create a nested follow for iterate adding value first for iterate between rows and
second fold trade between column four.
I call an equals zero I less than two.
And I + + follow condition is less than two because those numbers are two dimensional array two is two
and right four low for the columns for J.
Colin equals zero J less than two J + +
+ four.
Lu condition is less than two because columns number of two dimensional at eight weeks to now write
the value of each set for the example rows zero and column zero.
And it returns the value of zero zero seven zero zero in column one returns value of zero one set.
Now write the code if F percent, the back is less T and set the value of the array to sit.
I four row index and sit j full column next.
After end of each row, we go to the next line by the following comment Go to the next line.
And if he OK, he format the call, save the project and execute the code.
Now we can see the output, we see that the elements of each row and column are displayed separately
and printed in two rows and two columns by declaration the Varkey War in order not to prolong the time
of this session.
We will finish it and we will continue the content in the next session.
Goodbye.