 Hello and welcome to the video lecture on Introduction to 2D Array Using C Programming. At the end of this video lecture, students will be able to demonstrate the declaration and initialization of a 2D array and will be able to explain the concept of memory representation in a 2D array. The following topics will be discussed in this video lecture, 2D array, declaration of 2D array, memory representation of 2D array elements, initialization of 2D array. 2D array, what is the need of 2D array? Why do you need actually the 2D array, need of an 2D array? Consider a scenario where we are going to store student rule number and marks scored by him in one particular subject. In the same way, to store student rule numbers and marks of 100 students in different subjects we need to declare 101 dimensional array. Handling this variables in the program is quite complex. Therefore, we can use the concept of 2D array which will allow to store and access 100 values of 100 students using same variable name. In this way, 2D array is useful to make code simple. Definition of a 2D array. Two dimensional arrays are nothing but the arrays which are indexed by two subscripts, one for the row and the other for the column. Example may be a periodic table or it may be a lab book of multiple readings or marks obtained by three students in three subjects. So, if it is taken as an example like float marks rule number subject in which there are different rule numbers, there are different rule numbers of the students and the subject is different subject 0, subject 1, subject 2. So, there are different marks obtained by different students in different subjects. So, this may be an example for it. Now, we will be discussing about how to declare a two dimensional array. In order to declare a 2D array in C, a programmer specifies the type that is the data type of the elements, name of the array, row size and columns size required by an array as follows. That is type, array name, row size, column size. So, this type of array is called a two dimensional array. The row size and column size must be an integer constant greater than 0 and type can be any valid C data type. For example, to declare a 5 cross 3 array called stirred STUD of type int use this statement. Here, stud is a variable array with sufficient to hold up to 15 integer numbers. The size of this array will be 60 bytes as 4 bytes are required to store one integer constant. Float A 55. Here is a variable array with sufficient to hold up to 25 floating point numbers. The size of this array will be 40 bytes as 4 bytes are required to store one floating point constant. Character name 3 of 1. Here name is a variable array with sufficient to hold up to 3 characters. The size of this array will be 3 bytes as 1 byte is required to store one character constant. Memory representation of an array. Now, we'll be discussing about the memory representation of array elements in a 2D array. Suppose we have declared an array int as 3, 2. All arrays have 0 as the index of the first element which is called the base index and the last index of an array will be total size of the array minus 1. All the array elements will have garbage values assigned to it. So, it will be s of 0 0, s of 0 1, s of 1 0, s of 1 1, s of 2 0, s of 2 1. Now, this whatever we are saying 2686712, 2686716, 2686720, 2686724, 2686728 and 2686732. So, these are the address locations of the different array elements. Now, suppose when I assign a value to index 0 0, it means s of 0 0 equal to 1 2 3 4. The above statement assigns the 0th row and 0th column element in the array with the value of 1 2 3 4. Pictorial representation of the array which we have discussed above is shown below. So, all other elements other than the 0th row and 0th column index element will have garbage values assigned to it. Initialization of a 2D array. Initialization means giving some initial value. I am giving some initial value to the particular array element. The initialization of an array or 2D array can be done either in a single statement or one statement as follows. Int as 4 2 2 4 6 2 comma 4 6 comma 8 10 comma 12 14 comma 16. It means 4 rows and 2 columns. The number of values between braces cannot be larger than the array size. The row size is to be mentioned compulsory, whereas the column size can be omitted. So, this is another way. Int r num 4 empty column and I have assigned the values. It would be 2 1 1 3 5 7 9 11. In this array, I have initialized the array with row size equal to 2 and column size equal to 1, but I am assigning 3 values which will create error during execution of the program. Another thing is character n 1 empty bracket a b c d. So, this is a character array then int eid 4 1 11 12. In this array, I have initialized the array with row size equal to 4 and column size equal to 1, but I am assigning 2 values, whereas all other array elements will have a garbage value or junk value assigned to it. The garbage value is 0 for integer data type, 0.00 for floating point data type and null for character data type. Now pause this video for a few seconds and try to write answer to the question. Which of the following is the correct way to declare a multidimensional array int r 1 2 int r 2 3 both a and b none of that. So, so the main point we are discussed during the declaration of multidimensional array was you have to mention the data type of the array that is first and two are correct. Then you have to mention what is the array name, what is the type name and the array name then mention the row size and column size. So, as both of the options are correct a and b so it will be c both a and b is the correct answer. Now today we'll be discussing how to write a simple program for displaying marks obtained by three students in three different subjects using code block software. It means I'll be declaring int marks 3 3 comma i comma j. These are the two variables i and j for rows and columns. For i equal to 0, i is less than 3 i plus plus j equal to 0, j is less than 3 j plus plus slash n enter the score by the user slash n ending with a semicolon scan f percentage d ending with this. Now this is okay. Marks obtained by three students in three different subjects. So, I'm using print f slash n scored by the students, students slash n again for i equal to 0 i is less than 3 i plus plus bracket for j equal to 0 j is less than 3 j plus plus bracket again print f percentage d then as I want afterwards it should be in the separate line. So, I am using print f slash n slash t for for build. I'll go for compile. I'll go for run. I'll enter the marks 50 60 70 80 90 40 60 78 67. So, this is how I go get the output on the screen. These are the marks scored by the students in three different subjects. These are the following reference. Thank you.