 Hello friends, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I am going to explain how you can pass 2D array into a function in C language. Before start, just one information. If you go to description of this video, you will find links of various playlists related to C language. So you can follow those playlists to watch more programming related videos. So now I am going to tell you how we can implement this. So as I hope you know, function have three parts, declaration, calling and definition. So with the help of these three parts, I will be implementing this problem. So what I'm going to do, I'm going to add diagonal elements of 2D array. So in this video, you will learn how we can pass 2D array into function. And with that passing, how we can perform some of all the diagonal elements of the 2D array. And after calculating the sum, the result will be returned back to the main function and then we can create. So in this program, we will be having two functions. So first will be main and before main, I'm going to declare this function whose name is sum of diagonal and here I'm going to pass a 2D array. So this is the return type of function that is it. So this function will return and be integer value. Its name will be sum of diagonal. So name can be everything. If it is large, you can reduce it as per your requirement. And this is the argument or parameter. So in square bracket, I'm mentioning 3D. So it means this function will be receiving 3 by 3 2D array or processing. Now here I'm going to declare 3 by 3 array, 2D array, and I'm going to initialize values as well. So this way I initialize line value into this 2D array. So first row will be having 1, 2, 3, second row will be having 4, 5, 6 and third row will be having 7, 8, 9. Now I'm declaring one more variable that is S. Then I'm calling this function, so sum of diagonal and inside this I'm passing this array and then print S, sum equals to percent D and then S. So this way main function definition is complete and this part is declaration of function. This part is calling of function and when we call a function, so control automatically transfers to its definition. So here we have implemented only one function till now. That is main function, but we are calling one more user defined function that is sum of diagonal. So after completion of main block or body, we need to define definition of sum of diagonal function. So you can write int, then sum of diagonal, name of function. So you cannot provide any blank space in between these words. So remember that and int, int, int, int, int, int, int. So this name can be anything. You can use any variable name. You need to provide data type because this is separate to main function. So main is still here and after main, we are defining one more function. So that's why whatever you use as a variable in this block, you need to provide data type. And as indicated, declaration we mentioned, a 2D array will be of different size, so we need to put it here. So in case of 1D array, mentioning size is optional, but in case of 2D array, you need to mention these size so that it can work. Now I am declaring these variables so that I can process a loop. So here I am writing a loop. This loop will be repeating, first loop will be repeating three times and second is also repeating three times. Inside this loop, I am writing one F condition, if i w equals to j, then add a of i j into s. So this is the diagonal condition. If row index and column index both are same, then it means we are on diagonal function. So with this nested loop, sum of diagonal will be available and after completion of both the loop, I can write return s and I can close this loop. So here you can see this is the another block. So calling will transfer control here. This a will be transferred to here. This a 2D array will be processed. Result will be available into s. With the help of return keyword, I can transfer it back to this way and then it will be completed. So by calling of any function, control transferred to its definition and after completion of this definition, control again transferred back to its calling. Then result will be displayed. So if you have any return type as ink, float or cast, so you need to return that type of value of always whenever you are going to implement any function. So this way I hope you understood how we can pass 2D array into function. So in this example, I passed only one 2D array. If you want to pass more than one 2D array, you can put a column, mention data type and two square brackets along the sides, pass second variable from here and receive it here. So this way you can pass any number of 2D arrays into a function for processing. So I hope you understood how we can pass 2D array into a function and function is also a user defined function. So if you want to watch more programming related videos or let's say you want to learn about 2D array or function mode. So at the end of this video, I have attached a playlist related to those. Also, if you want more programming related videos, go to description of this video. So there you will find a playlist related to each and every topic that are in C-lambers. So do watch them and thank you for watching this video.