 Hello friends, I am Sanjay Gupta. I welcome you on my YouTube channel. You can watch various programming related videos on my channel. It contains more than 800 videos. You can search those videos through the keyword programming by Sanjay Gupta. In this video, I am going to demonstrate you how you can pass a 2D array into a function in C programming. And for demonstration purpose, I am taking an example which will find out some of diagonal element of a 3x3 matrix. So first I am going to include a header file stdio.h. Now I am going to declare a function. Name of function is sum. Its return type is int and it will receive an argument of integer type which will be a 2D array of 3x3 dimension. So this is declaration. After this declaration, I am going to define main function definition. Here I am declaring a 2D array and some variables. To receive values from user, first I am going to display a message. Enter values with the help of this printf. Now to read values from user, I am going to implement nested loop because 2D array contains more than one rows and columns. So with the help of this nested loop, I am going to iterate scanup statement which will read values for this 2D array. So this nested loop will be reading all the elements of 2D array and those elements will be stored at different indexes of array A. Now I am going to call the function sum and inside this function, I am passing 2D array whose name is A as an argument. So this is calling of function. As you can see, this calling statement will be receiving the returned value in S variable which will be the actual result. So I am going to display that on output screen with the help of printf. So this way I have implemented the definition of main function. Now I am going to implement definition of sum function. So this block is definition of function. Inside this block, I am going to calculate sum of diagonal. So for calculation purpose, I am going to declare some variables. Now again I am going to implement nested loop so that I can process diagonal values. Here I am using a condition if I double equals to 0. So if I and J both are equal, it means we are pointing to diagonal element. So here I is representing row index and J is representing column index. So if both are equal, then I can add element of 2D array into variable S. So finally S will be containing sum of diagonal values. So I can return it and this returned value will be received through calling statement which is available at line number 13. So this way I have implemented the complete code in front of you where I am passing 2D array as an argument in a function. Now I am going to execute this code so that we can check whether it is working properly or not. So entering three matrix values and you can see the output. Sum equals to 15. So here diagonal elements are 1, 5 and 9 and if we add all these elements, then sum will be equals to 5. So this way program is working properly. I hope you understood how we can pass a 2D array into a function in C program. If you want to watch more program related videos, you can watch my YouTube video. Thank you for watching this video.