43 - TWO DIMENSIONAL ARRAYS - C PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome to our Channel so in the previous sessions we have seen the one-dimensional arrays and in this session let us have a look on two-dimensional arrays so as I as we discussed in the previous session that one-dimensional array will be having only one subscript and here we are using the two dimensional array so that way that we have must have the two subscripts so may be this two dimensional array is used where the data is represented in a row and column corner that means if the data is in a tabular format then we can use this two dimensional arrays so as we know that an array is a collection of elements with similar data type so here also the two dimensional array is also the direction of elements which are of same determined here the difference between one equation two dimensional its subscripts so mainly this one as I said that this two dimensional array is used to represent the tabular data so one one subscript represents the row and another subscript represents the column so here two dimensional so here we'll have two subscripts so as we know that subscript is this one so here we have two substrates and next these are used to represent tabular data where data is represented in table those data can be represented using two-dimensional so one subscript represents the rows and second subscript represents them so here 1 subscript represents the rows and how the subscript represents the columns and the problem of elements that the two dimensional address those rows and into columns so this multiplication will give the maximum number of elements that they're dual dimensional Eric and restore and whatever the rules we have followed for one dynamics will rather the same rules to be followed by them two dimensional array also so we have to give a name for the two dimensional array also similarly we can represent it as something and in the whole size column size so we have to mention both row size and column size so here also the index starts from 0 this also it starts from 0 so here we have to make sure two sizes that is one is for hole and the one is per so let us see here syntax for declaring a two-dimensional array right in the data tag followed by harry name with row size and column size so we have to make sure the rows and column size so as in the fundamental error we can give a maximum number and then in the program we can read the required number of rows adequate number of columns so what in the declaration we have to give the number the size of a row and Syria example so if we the best application or the best example for this tool a pixel array these matrix matrix data so as the matrix can be represented as a rows and columns so Mattox yeah with called rows 3 and 3 so this is the name of a variable V a which is having the row size 3 and column size thing here the row size 3 means the index value starts from 0 0 to 2 0 1 here also the column size is 0 0 1 0 to first row second row 0 column first column and second column and our question is how the elements will be stored in the and so as in the one dimensional array always the elements stored in index jr. and immediately there one immediately then 2 3 4 and so on yeah but in this to damage Solaris there is a pool sizes that is one is wrong another one is column so how the elements are stored in the two dimensional so here they are stored in row column or row voice honor so first the first term will be a saint and then the second row will be assigned and then Terra will be basing and followed by the L throat will be a same so that means the first value will be assigned to 0-2 Zenith column next 0th row first column 0 through second body then first comb 0 column first row first column first row second one second row 0 column second row first column second row second column so so this is the order how the elements are stored in two-dimensional array of size 3 by 3 so bra ways it will be a same so for after finishing the first row the second row will be a saint C so after finishing the first row then the second row will be started and after finishing the second row the third row will be started so the first element is this one second a third a fourth element fifth element six seven eight so as I have said earlier the number of total number of elements that the Eric and Stroke is rows into size here the rows are three and the columns are three so rows into columns gives them the maximum number of elements that the two-dimensional array can store so if this array yay it can store a maximum of three v 9 elements so these are the nine minutes so first row will be created that may serve all role elements will be a sane then second row then third he also the index always start from z no for after declaration we have to see the initialization how to initialize a variable added so as in the one direction that is similar is equal to by using an assignment operator we can assign the values that means that we call it as compile time initialization and let us see the compiler and initialization compile an initialization in May of 3 3 is equal to open the curly braces the same thing we have done in the one-dimensional and open again another curly braces right on the elements of first row so here there are three rows and three columns so three rows and three columns so each o'the will be having three columns that means three elements we can resend to three so this second curly braces represents the four elements come on the second row come on third this implies this belongs to zero troll this belongs to first home this belongs to second home so here the rule is zero one and two triples and in the do not roll this one is a zeroth element do not call first column second column again 0th column first column second column 0th column first column second column so this represents the rule and this represents the so three rows and here also take all the 0 1 & 0 through first row second row 0th row 0 column zeroth row first column 0 through 2nd column first row 0 column first row first column and first row second column similarly second row 0 second row first column and second row second column now this can be represented in the matrix as 1 2 3 4 5 6 7 8 & 9 so this matrix can be assigned in this way first row second row and the third row and similarly if you ascend any single value or single element in an array all the elements in the remaining area will be initialized to 0 so if you declared and if you are failed to initialize or if you are not initialized if you deserve initialize any value to that array elements then by in it by default there will be garbage values for all the elements if you initialized at least one element among these my element automatically the remaining elements will be 0 and this can also be written as 3 3 is equal to 1 so simply we can write this zero so if this implies this is the first element initialized to zero automatically all the remaining elements will be initialized to zero and if it is 1 it will be initialized to 1 first element and all the remaining 3 8 elements will be initialized to 0 and also we can write 1 2 3 4 5 6 7 8 and 9 so this is the same statement of this one so we gave we are not separating the wrong items with directly right if all the elements so automatically the compiler will treat the first element as 0 0 second element as 0 1 third and in 1002 as the 2 is the last element of all again the next one is first row 0 column first row second row first column and first row second column and the next one it will treat it as the second row 0 column second row first column and second row second row so these are the many alternatives how the array can be initialized at that one can't combine them so now let us have a look how to initialize an array in the runtime so that can be initialized at the runtime by using only one function that is scanf function so as we have said seen that printf and scanf functions in the earlier sessions so if you are having any doubts once referred on the second session so if you want to initialize any variable in the runtime then automatically we have to lose the scanf function so for reading all the elements into the two-dimensional array obviously we have to use the scanf you have to repeatedly execute the scanner so that means we have to use the loop statements that means iterative statements for reading all the elements into and for I is equal to zero I guess then Ross ice I plus Chris so this statement for who next I J is equal to 0 J less then concise J Christmas so this statement is scanning percent is D hammer same yeah I so this is a simple logic fun reading all the elements into two-dimensional and so first loop is for no and the second group is for column so this means first is equal to 0 I less than or equal to row size until this condition fails the neutral be repeated the control will repeatedly execute the same same set of statements so inside this for loop again we are hiding the fargo j is equal to 0 J less than column size so that means whenever this condition fails then the control will go out from this loop and I will be incremented that means 4 is equal to 1 J will be implemented J is equal to 0 with the same J's equal 1 redressing J is for the to embarrassing if process is 3 in kansai system when J is equal to 3 finish some comes out from the loop I will be incremented for I is equal to 1 again J is equal to 0 J is equal to 1 J is equal to 2 J support three in a game face again a controller comes out from the loop I is equal to 2 J is equal to 0 there is put one day's equal to J is equal to 3 again here case the control comes out from the loop now I is equal to 3 it also fails so it stops reading the values into two-dimensional and so in this way we can read all the elements of two-dimensional now the question is how to print all the values of two-dimensional and simply the same logic will be implemented instead of using the scan why is the printed so that how the elements will be displayed repress them sorry erase the Amazon one so person tasting of ID so every element will be printed so 0 first 2 0 0 0 1 0 2 next I will make amended 1 0 1 1 1 2 next Jake will be incremented 0 sorry I will be getting limited to 0 to 1 2 so like this way we can raise the elements into 2 dimensional array and we can print the elements of 2 dimensional array so for this we have to use two different loops so nested loops this is called a nested loop we are writing loop inside the another so first two outer loop is for who mentioning the roll and the inner loop mentions the column hope you understood this and let us write a program to read and write the elements of two-dimensional main function now because added through in a of some 10 20 or simply take it as three entry Triple D right no 4 is equal to 0 I less death 3 I plus plus again for J is equal to 0 J less than 3 J plus plus scan percentage D am present a of I and Z so this is the ready now again print the same movements per is equal to 0 I less than 3 I plus plus for J is equal to 0 J less than 3 J plus plus printf percentage D and yeah I so this is a simple program for reading and writing the elements of two-dimensional area so this process is for reading and this process is for this plain display so this implements who this improvements here also this implements elope this implements so hope you understood this is a simple concept two-dimensional area so where these four dimensional address will be used so whatever the tabular data will want to represent then we can go for this two-dimensional and the example based example is semantic representations so all the matrix applications we can use this two-dimensional formatic for performing the matrix addition matting subtraction and matrix multiplication and transposing the more matrix so for everything we can use this two-dimensional arrays concept hope you understood this session and if you like my videos do subscribe to my channel and share my videos with your friends and if you are having any doubts regarding our C language please feel free to post your doubts in the comment session so differently I will try to clarify your doubts regularly and thanks for your list of thanks for listening my sessions and thank you
Info
Channel: Sundeep Saradhi Kanthety
Views: 116,174
Rating: 4.9075232 out of 5
Keywords: c programming, c language, compiler, c compiler, binary, object code, c code, coding, exe code, .c, .obj, .exe, c files, sundeep, saradhi, kanthety, cp, computer basics, programming, software, c programming language, c language for beginners, arrays, two dimensional arrays, 2D arrays, subscript, index, matrix operations, runtime initialization, array declaration, array initialization, reading elements into an array, display elements of a 2D arrays, n dimensional array
Id: vyOZcg4cPRY
Channel Id: undefined
Length: 21min 23sec (1283 seconds)
Published: Wed Oct 04 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.