 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can reverse an array by swapping its elements and you have to pass array into function. Before starting, you can note my information, you can follow or subscribe my YouTube channel through the URL youtube.com slash sanjaygupta underscore tech school. You can download my programming app Techimace which is available on Google Play. Now coming on to the topic here in this video I am going to demonstrate you how you can print reverse of array by swapping its elements like first element and last elements will be swept second and second last will be swept and so on and you have to pass array into function. So here in this program which is which will be implemented in C. I will use two features of C that are array and functions together. So first I am including a header file stdio.h then I am declaring a function reverse and I have to pass only one argument that is array so this statement is function declaration. Then I am defining main function inside main function I am declaring an array and I variable then printf statement which will display the message enter 10 elements on console. Then for loop this for loop will receive elements from user with the help of scanf. So using these three statements printf for and scanf all the elements will be received from user inside array now I am going to call reverse function and I am passing array a inside it. So this statement is function calling now after function calling I am using printf which will display the message reverse of array on console and then a loop which will repeat 10 times and it will display the elements of array with the help of printf on console. So this way I have implemented the complete definition of main. You can see first segment of this code is reading the elements from user then I have called reverse function in which I have passed a array and then after completion of calling the values a arrays will be displayed on console with the help of these three statements. Now I am going to implement definition of reverse function. So this block will be containing function definition. So now I have to create the logic so that I can reverse elements of array by swapping them. So first element will be swapped with last element of array. Second will be second last and so on. So I am declaring two variables i and j then I have to implement a for loop. Inside for loop I have initialized i with zero and j with nine. Now condition is i less than j. So if i is less than j then this loop will repeat otherwise it will be terminated and then i plus plus and j minus minus. So here you can see two variables are used to mention indexes i and j and if elements are 10. So I have to repeat this loop only five times because in one rotation two elements will be swapped. So that's why I have mentioned this condition whenever a value of i is less than j then only this loop will repeat otherwise it will be terminated. Now I have to apply the logic for swapping. So I am using a temporary variable t then t equals to a of i then a of i equals to a of j. So a of i is representing first location and a j is representing last location. So this time I am swapping a i with a j. So i is representing zero and j is representing nine. So zero and nine index values will be swapped here. So last statement will be a j equals to t. So this way complete swapping instructions are available. So this loop will repeat five times because size of array is 10. So that's why beginning five elements will be swapped with last five elements with the help of this for loop. And the swapping operation is done with the help of third variable. You can also implement this logic without using third variable. So now one more thing that you have to understand when I called reverse function I passed a array inside it and definition received a array elements. So I am changing or I am swapping elements in reverse function definition. But while I will be completing this change or swapping the actual array which is available at calling statement will be updated automatically. That's why this reverse will be displayed in main function only. So you have to remember that whenever we pass an array into a function definition and we modify elements of the array then actual array will be modified automatically because in case of array see uses the concept of call by reference that is managed with the help of pointers. So internally array is using pointer. That's why the definition will be modifying the array and the calling will automatically receive the modified values. Now I am executing this code. You can see it is asking for 10 numbers. So I'm entering 10 values. You can see the output reverse of arrays 10 9 8 7 and so on. So friends this way I have swapped the locations physically inside array with the help of function. Now I can remove this J from this loop and I have to repeat loop 10 times sorry 5 times. So I am using I less than 10 by 2. So 10 by 2 means 5. So this loop will repeat from 0 to 4 because less than is available here. So 5 times this loop will repeat and in place of J I am using 9 minus I. So you can see initially I is 0 so 9 minus I will be 9. Then next time when I will be incremented so it will become 9 minus 1 that is 8. So that's why 9 8 7 6 and so on will be available in place of J with the help of 9 minus I. So we can remove J from this loop and we can implement this logic with the help of I variable only. So again I am going to execute this code. I am entering 10 numbers. You can see the output reverse of arrays displayed properly. So friends I hope you have understood how we can print reverse of array by passing array into function and I have swapped the elements of array physically by swapping first last second second last elements and so on. So you can also implement this logic in your laptop or desktop so that you can understand it well. I hope you have understood how we can pass array into function and how updated array is reflecting the function call. So that we can print the result of updated array in main function. If you want to watch more programming related videos you can follow or subscribe my YouTube channel that is youtube.com slash sanjay gupta underscore tech school. You can download my programming app Techimage which is available on Google Play. Thank you for watching this video.