 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can find out maximum and minimum element from an array using dynamic memory allocation. Before starting, you can note how you can search my YouTube channel. You can type my name Sanjay Gupta in YouTube search bar. My channel will be available on first page. You can open it here. Various programming related videos are available. So you can improve your programming skills by watching these videos. Now I am going to implement the solution of this problem. So first I am including a header file stdio.h then another header file that is stdlib.h. Now I am defining main function. Inside main, I am declaring a pointer p variable n i then max. I am initializing it with minus three two seven six eight n variable min which is initialized with seven three two seven six seven. Now with the help of printf, I am going to display the message enter size. To receive this size from user, I am applying scanf and that size will be stored inside n variable. Now for dynamic memory location, I am calling malloc function. So this statement is performing dynamic memory location. So here malloc is called which is having n into size of n. So this size will be allocated and this that address will be typecasted into integer pointer and will be stored inside p pointer. Now through p, I can access all the locations of that allocated memory. So now the message and the elements will be displayed to receive the elements I am applying for loop which will repeat n times. Inside this loop, I am writing scanf statement which will store elements at p plus i location. So p is having base address every time I am adding i in p. So p will be incremented and next locations of that memory location will be available. So the entered values will be stored at p plus i locations. Now I can apply if then asterisk p plus i will be compared with max. So this is first condition if asterisk p plus i is greater than max. So p plus i is pointing to the address and to identify its value. I am using asterisk. So it is dereferenced down if value at that address is greater than max. I can assign that value into max variable. So this way maximum is checked. Now I can check minimum. So I am applying if asterisk p plus i is less than min. If this condition is true then min equals to asterisk p plus i. So this way I have compared asterisk p plus i with max as well as with min. So if any one of the condition is true then max and min will be modified. This process will repeat n times after completion of this loop. The result will be available in min and max variable. So I can print these results on console like this and then I can call free function so that dynamically allocated memory can be freed at last return zero. So this way I have implemented the complete logic in front of you. How can we find out maximum and minimum from an array using dynamic memory allocation? Now I am going to execute this code. It is asking for size. I have entered 10. So I am entering elements now. So you can see the output maximum equals to 89 and minimum equals to 1. So I have entered random values in the array and it is printing correct result on the console. Now if I again execute this code this time I want to check only four elements. So this time I am entering only four values. You can see the output maximum is 6 and minimum is 2 and you can also see the desired input is received through this program because it is implemented with the help of dynamic memory allocation. So in case of dynamic memory location size of array will be provided by the user but in case of static it is provided by the programmer. So this way I have implemented this logic in front of you. I hope you have understood it. If you want to watch more programming related videos you can search my channel through my name Sanjay Gupta on YouTube. So keep watching programming related videos so that you can improve your programming skills. Thank you for watching this video.