Function pointers and callbacks

  Рет қаралды 337,451

mycodeschool

mycodeschool

Күн бұрын

Пікірлер: 179
@OzieCargile
@OzieCargile 7 жыл бұрын
You are the best C language instructor I've found on KZbin. Clear and concise.
@oleksijm
@oleksijm 4 жыл бұрын
You are so right.
@yasserosama3405
@yasserosama3405 7 жыл бұрын
Using a function pointer instead of just calling a comparison function is more useful because then you can create many different comparison functions and still use that one sort function. This means you no longer have to have direct access to the implementation details of the sort function, thus helping to keep things cleaner and easier to see/manage. (this is not my comment , it's a reply to a question 3 years ago from now , I pasted it so new people coming could see it and maybe help them understand the real benefit/use of function pointers)
@cbeHotboyred1614
@cbeHotboyred1614 7 жыл бұрын
Man !!! You explain everything so great. I was so confused on this topic before your video. I had a similar program like this and need a way to change the comparison operator like < ,> !=, and == , but I didn't know how!! So i always just wrote duplicate code to change just one thing in it. Thanks, you explain everything perfectly!!!
@baconsledge
@baconsledge 2 жыл бұрын
You explained everything about sorting but little about function pointers and callbacks. Like when a call back is really useful.
@Blaqueken
@Blaqueken 8 жыл бұрын
The best online teacher on the Internet so far... as I'm concerned. Bravo! These concepts flew over my head back in class but now i understand. What a talent this guy. Very inspiring...
@nawinksharma
@nawinksharma 6 жыл бұрын
Thanks for separate series on pointer, this helped me in embedded system topic
@chandrashekhar9693
@chandrashekhar9693 5 жыл бұрын
In Bubble sort program (4:42), unnecessary looping we can use for( j = 0; j < n - ( i + 1); j++) instead of ( j = 0; j < n -1; j++)
@evertdekker3915
@evertdekker3915 9 жыл бұрын
Thanks, watched them all. Easy tot understand the basics of C with these video's.
@jianxiaohu8213
@jianxiaohu8213 4 жыл бұрын
This eps is another level!
@shivkrishna6157
@shivkrishna6157 9 жыл бұрын
10:13 why do you have to pass function pointer when you can use the "function compare" directly inside "the function BubbleSort"
@Phantom1037
@Phantom1037 7 жыл бұрын
Inside the main function when we called the bubble sort function, we gave as arguments : ( A, 6, compare). - A is an array and it returns the address of the first element, so the function declaration of bubbleSort should have the first argument as an pointer to iteger. - 6 is an integer so the second argument of the bubbleSort function should be an integer. - compare is a function and it returns the address of the compare function, so we need to pass a pointer to function as the third argument to the bubbleSort function.
@Arjunreddy-xi5ht
@Arjunreddy-xi5ht 7 жыл бұрын
if there are more than 1 compare functions,instead of changing the code everytime you can just use a function pointer to call the required function and make the required comparison.
@KshitijKale
@KshitijKale 4 жыл бұрын
My guess, it has something to do with the scope of the function. Since all the functions in the given example are global; they can be called effortlessly anywhere. But if some function was inside the main or any other function then it wouldn't be possible to directly call the function and hence a function pointer should be used.
@KshitijKale
@KshitijKale 4 жыл бұрын
Ok, this one makes more sense. In the example of sorting integers using a pre-built quick sort algorithm we directly use the function. But since the definition of the actual function is not provided instead an extra parameter is allowed to be defined by the user himself so that they can still use the algorithm for quicksort and also make their own ranking function. In this way the source of code of qsort is safe and functionality is also maintained. If instead, we couldn't pass the function pointer then we would have to directly alter the qsort algorithm which in this case might even be possible but many times the source code isn't available. I hope this helps after this many years and please do share any insight that you might have discovered.
@ediccartman7252
@ediccartman7252 8 жыл бұрын
Very good explanation, BUT.......For summary it would be useful to bring the code with both cases , like : void main() { int order, counter, a[ SIZE ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 }; printf( "Enter 1 to sort in ascending order, " Enter 2 to sort in descending order: " ); scanf( "%d", &order ); ................................. if(order==1) Bubble(a,size,ascending); .......................................................... else Bubble(a,size,descending); And then it's clear, that in the1st case the function pointer will point to ascending , and in the 2nd - to descending.
@shubhamsuraj2725
@shubhamsuraj2725 4 жыл бұрын
dil jeet liya bhai ye video :)
@certified_car_simp1856
@certified_car_simp1856 Жыл бұрын
wow this is so understandable if you're a beginner, great job
@NishantSingh-yt9em
@NishantSingh-yt9em 4 жыл бұрын
Thank you for your efforts in explaining tricky things so easily.
@ericliudev
@ericliudev 9 жыл бұрын
Hi, this is an amazing series of tutorials. The pointer to function is really interesting, however, language like Java doesn't have this mechanism. I guess we will have to use 2 classes to implement an interface and pass the interface as a argument to the method to achieve the same design.
@yuvraj7214
@yuvraj7214 3 жыл бұрын
Java does have pointers.
@moyam01
@moyam01 9 жыл бұрын
What is the difference between using the function pointer, and calling the compare function directly? for example, if within the sort function you just call compare(), and return the result. I've done something similar in Visual Studio, and it compiled and worked.
@lautarodelucia6480
@lautarodelucia6480 7 жыл бұрын
What comes to mind is that you cannot change the sorting order from main in that case. By using function pointers you could define two compare functions, one for increasing and other for decreasing order. They would only differ in the order of the returns ( swap 1 for -1). Then you can use command line arguments, for example, to choose your sorting order without touching the code.
@milanpatel3159
@milanpatel3159 5 жыл бұрын
the thing here is that if you don't have write permission to the BubbleSort() definition you can change sorting behavior from the main function. No need to touch BubbleSort()
@saeidsaati4021
@saeidsaati4021 4 жыл бұрын
Great tutorial with a good explanation thank you, I just think that in 14:34 const is using for preventing to change the "value" of the pointer not the address of it.
@AmitYadav-rp3ot
@AmitYadav-rp3ot 4 жыл бұрын
Correct!
@nikhilk7493
@nikhilk7493 4 жыл бұрын
9:29 you replace n-1 with i in inner loop
@saurabhsoni5047
@saurabhsoni5047 7 жыл бұрын
Good example used. Thumbs Up for that.. Although, Regarding the compare function prototype for qsort in the last where you make the statement "const keyword is used here so that you cannot change the address stored in this pointer variable" It should be " cannot change the dereferenced value for that pointer variable "
@flywittzbeats4008
@flywittzbeats4008 7 ай бұрын
This is perfect haha, thank you. Makes so much more sense
@alisalamatian2418
@alisalamatian2418 3 жыл бұрын
Thanks for all of your videos. I really find them useful. I just still do not understand why we should use a function pointer when we can directly call the function. Could someone explain the difference to me?
7 жыл бұрын
It was really helpful. Thank you for the tutorial.
@rd-tk6js
@rd-tk6js 6 жыл бұрын
Thanks, excellent series on pointers !
@saivenkat
@saivenkat 3 жыл бұрын
Lets say you are designing a library function that would do something like sorting so anyone can just use your library function and sort. And you want to keep this sorting function generic, so data type can be anything. Then, how would you take the required information to sort from user of your library function? You cannot guess the comparison logic for a complex daya type. So, you would want to get the comparison logic too which can be passed as a function. So, in many cases when we are dealing with generic scenarios, function pointers make our life easier. It should be seen as a way to accept functionality as argument. So far, we knew that functions can accept only data, but now we know that even a function can be passed.
@rmarinero
@rmarinero 5 жыл бұрын
I understood this within the first and a half minute, amazing and clear explanations!
@himanshusingh-sh7ih
@himanshusingh-sh7ih 10 жыл бұрын
You made my concept very clear! Thanx a ton :)
@emmanuelakpabio9529
@emmanuelakpabio9529 Жыл бұрын
This is super duper amazing!😊
@ToanPhan03
@ToanPhan03 8 жыл бұрын
At 11:04 why we dont need to change *compare to *absolute_compare in void BubbleSort(.....) function. Also compare(A[j], A[j+1]) to absolute_compare(A[j], A[j+1]). But it still works fine because the value store in memory where pointer *compare point to?
@ankan2088
@ankan2088 8 жыл бұрын
nice observation. The bubble sort if you notice carefully takes the argument (A, 6, absolute_compare). So the int (*compare)(int, int) declared inside the void BubbleSort(int *A, int n, int (*compare)(int, int)) points to absolute_compare function instead of the compare function. Even if you changed the compare inside BubbleSort to another name( say, int (*ptr)(int, int)) it would work fine. I hope I explained it clearly. :)
@nakulnair497
@nakulnair497 7 жыл бұрын
I still didn't understand why *compare wasn't changed to *absolute_compare in bubblesort func definition
@ibiixie
@ibiixie 8 жыл бұрын
Had no idea this was possible, this sure will make my GUI system a lot easier to create! :>
@venkyreddy5507
@venkyreddy5507 10 жыл бұрын
Awesome explanation bro.I really wondering that how could you do that.
@abhimanyumishra9455
@abhimanyumishra9455 9 жыл бұрын
Amazing Explanation!!
@prankurhauhan
@prankurhauhan 6 жыл бұрын
Hi, Thanks for the explanation it was great!!. just a remark/question: at 14:33 you said const void* a , we cannot modify the address that 'a' points to , which means you are implying 'a' is a constant pointer, but I think it is that the variable pointed by 'a' cannot be modified, means the *a = 3 is not allowed and a = &someOtherVariable is allowed.
@antilogism
@antilogism 5 жыл бұрын
The "const" qualifier has the same effect on a pointer as it does on any other variable. Pointers, like a and b, are just variables containing an address and, with that qualifier, must always have the same value. However the data stored at those addresses are not bound by the qualifiers on those pointers. The data will follow the declarations that allocated the storage in qsort().
@AmitYadav-rp3ot
@AmitYadav-rp3ot 4 жыл бұрын
@@antilogism Pointer to constant { const int *ptr } This indicates that the content at the address pointed by ptr cannot be changed, but changing the address pointed by ptr is allowed to change. Constant pointer to variable { int *const ptr } This indicates that the address pointed by ptr cannot be changed, however the content of the address is allowed to change. source: www.geeksforgeeks.org/const-qualifier-in-c/
@Littleangel1306
@Littleangel1306 11 жыл бұрын
Thanks man your explanations are really good..........I appreciate you.
@darshilmodi6888
@darshilmodi6888 5 жыл бұрын
brillaint example and amazing explaination !! Keep going
@amalkms
@amalkms 10 жыл бұрын
yours videos are really helpful , thank you very much ....
@syfaiz
@syfaiz 5 жыл бұрын
Splendid explanation!
@MrJayesh05
@MrJayesh05 9 жыл бұрын
Brilliant job. Keep it up guys.
@Heizler
@Heizler 6 жыл бұрын
Very good explanation! Thanks!
@chesteringosan6039
@chesteringosan6039 4 жыл бұрын
add: bubblesort(...){...for(...){int x =0;...for(...x += 1;){...}...if(x==0){break;}}} from a newbie with c, this additional statement will break when the array is already arranged, because the example from the video will loop as many as indicated in the arg, even if the array is already sorted
@chesteringosan6039
@chesteringosan6039 4 жыл бұрын
add the x += 1 inside the if(A...){....here>>x++;}
@ahbarahad3203
@ahbarahad3203 4 жыл бұрын
A very interesting use of function pointers that i have seen in real life projects is in Event Handling while passing delegates/function signatures to functions, under the hood its basically the same thing except the delegates also have an iterator.
@ahbarahad3203
@ahbarahad3203 4 жыл бұрын
Oh he mentions it at the end of the video, lol
@XieQiu
@XieQiu 8 жыл бұрын
thank you for posting this.
@bibinio100
@bibinio100 11 жыл бұрын
Thanks a looooooooooooooooooooooooooooooooooooooooooooooooot of you are a wonderfull teacher !!!!!
@jackofnotrades15
@jackofnotrades15 5 жыл бұрын
Hi, I need a bit of clarification about what you said at 14:38 about function parameter being const. You said it is passed as const because the address shouldnt be modified. But does it signify the address not being modified or value inside the address not be modified? Basically whats the difference between const void *p and void* const p?. Please reply
@Rohitsingh2410
@Rohitsingh2410 5 жыл бұрын
He is dead bro. yourstory.com/2014/06/techie-tuesdays-humblefool
@jackofnotrades15
@jackofnotrades15 5 жыл бұрын
@@Rohitsingh2410 I didnt knew that. May his soul rest in peace. And may be someone notice my comment and respond. May be he himself in someway.
@AmitYadav-rp3ot
@AmitYadav-rp3ot 4 жыл бұрын
///////////////////////////////////////////////////////////////////////////// Pointer to constant { const int *ptr } This indicates that the content at the address pointed by ptr cannot be changed, but changing the address pointed by ptr is allowed to change. ///////////////////////////////////////////////////////////////////////////// Constant pointer to variable { int *const ptr } This indicates that the address pointed by ptr cannot be changed, however the content of the address is allowed to change. source: www.geeksforgeeks.org/const-qualifier-in-c/
@MustafaTaqi
@MustafaTaqi 11 жыл бұрын
Thanks a lot, you are really doing a great job
@harshith_takkala
@harshith_takkala 2 жыл бұрын
Awesome one
@manjunath.r1513
@manjunath.r1513 11 жыл бұрын
it is really good sir thank you sir!!!!!!!!! keep going with your good job!!!!!!!!!!and help student like us.!!!
@anurag8725
@anurag8725 8 жыл бұрын
Why are we using a separate compare function when we already have compare (< or >) in our bubblesort function. How are we using this compare in bubblesort function along with"". Where is the user input flag you were talking about.
@billigerfusel
@billigerfusel 8 жыл бұрын
Wooot this is awesome explanation
@MartiinCarrillo
@MartiinCarrillo 5 жыл бұрын
Great explanation!! Thanks a lot!
@adithyashankar6562
@adithyashankar6562 7 жыл бұрын
Good explanation on callbacks
@anghelutadragos1898
@anghelutadragos1898 9 жыл бұрын
Could you list some exercices for this playlist about pointers ?
@Addu1902
@Addu1902 6 жыл бұрын
Please
@hirokaanf4287
@hirokaanf4287 10 жыл бұрын
why the first program (from the beginning until 2:39) is not working id u keep return 0; in the main function?
@mycodeschool
@mycodeschool 10 жыл бұрын
return 0 is main function is not forced by most compilers. Mine does not. So, often we do not write it.
@kanwarpandit8798
@kanwarpandit8798 4 жыл бұрын
Bhai. Kmaal Kar diya
@souravsingh763
@souravsingh763 4 жыл бұрын
I was so confused with callback function working in JavaScript As i am familiar with c/c++ this callback in c and in JavaScript are same Thanks 👍
@mehulshah8470
@mehulshah8470 10 жыл бұрын
can u tell me the advantages of function pointer over calling function directly ?
@whydiswhydat
@whydiswhydat 2 жыл бұрын
where are the arguments being passed from into the comparison function? I think form actual A[ ] right? If so, is it just comparing the first two numbers, 3 and 2, and proceed from there?
@jamesward2946
@jamesward2946 7 жыл бұрын
This is great stuff!
@adityakrverma612
@adityakrverma612 10 жыл бұрын
Question to "mycodeschool" : this is really good video. Thanks for explaining. but question is how we are doing callback. It looks like regular calling of function when you call 'compare' inside bubblesort. Is that you mean is callback ? Can you please elaborate on callback. Also in the end of video you mentioned about callabck and event handling. That's what i am interested in. Is there any video or link on that ? Thanks !
@harikumar-cq1je
@harikumar-cq1je 3 жыл бұрын
I had the same question too. What's the difference between calling a function pointer and a normal function? I feel both do the same right?
@sxve-x
@sxve-x Жыл бұрын
8 years on and I have same question.
@nishanthkr2838
@nishanthkr2838 5 жыл бұрын
Thats some high level thinking there.
@roshenw
@roshenw 11 жыл бұрын
Thank youu soooooooo much really clear and helpful!!!!
@Jonathan-ru9zl
@Jonathan-ru9zl 2 жыл бұрын
thank u . keep up the good work
@cbeHotboyred1614
@cbeHotboyred1614 7 жыл бұрын
Do pointer function release its memory like the a regular function does when it finish executing OR do i have to delete it. If i have to delete it, How?? Is it possible to delete the pointer function ...... like the way you delete the pointer variable in c++.
@nickeax
@nickeax 4 жыл бұрын
Amazing, thank you very much.
@anmoljain1012
@anmoljain1012 3 жыл бұрын
you are most welcome!
@BYugandhar
@BYugandhar 7 жыл бұрын
Thanks a lot sir for providing good explanation, but I don't get one thing while calling compare form main. From where it's taking
@dawoodfarooq3605
@dawoodfarooq3605 8 жыл бұрын
Amazing. Keep up the good work (Y)
@vaibhavsingh4108
@vaibhavsingh4108 4 жыл бұрын
@10:50 the function Bubblesort takes argument as (int array, int n, int *compare (int,int) but when in main we call this funtion we pass argument as (array , n, absolute_compare ); which is another function . How this is happening , I mean we can how we can pass this . Anyone please help
@chaitanyabade9126
@chaitanyabade9126 4 жыл бұрын
Technically, absolute_compare works as an actual parameter and int *compare (int, int) work as a formal parameter, So if you pass any function as a parameter it will work until and unless the signatures are the same, different names doesn't matter.
@vaibhavsingh4108
@vaibhavsingh4108 4 жыл бұрын
@@chaitanyabade9126 thanks
@aadeshmehta
@aadeshmehta 7 жыл бұрын
Hi, Thanks for the video. You explain really good. Which editor have you used? It seems really clean and helpful with function definitions and syntax. Are there any other such editors you recommend
@harikumar-cq1je
@harikumar-cq1je 3 жыл бұрын
Even though the explanation is awesome. Still, I don't understand What's the difference between calling a function pointer and a normal function? I feel both do the same right? Even though you call Compare as a normal function that also does the same right? doe that makes any difference internally through memory?
@ChienChiWang
@ChienChiWang 9 жыл бұрын
Hi~~ I have a question. What are the variables the void pointer a and b in the function compare point to, after the program executes the function qsort ?? Will they point to elements in array A?? And the effect of return value of compare is to swap the two values in the elements?
@dn9255
@dn9255 5 жыл бұрын
I don't get it. So why do we need to declare function pointers if we can just call the actual function like you did in the last example?
@VikasPoonia
@VikasPoonia 5 жыл бұрын
In other programming languages we need this, like when an application waits for data and other things should be carried out. Like on KZbin, when you are watching a video, the next byte of the video should be downloaded. Suppose we have two function nested.. The first start the video and the nested one download the next byte of video to be seen. So the first executed itself but the second one is still waiting in memory for its required data. I hope you got it. We have in JavaScript: callback functions, async await and promises works on similar principles. function 1===> I am doing this. Function 2 ==> I am waiting for the next byte will return this as soon as I received it
@ahmed_raaphat
@ahmed_raaphat Жыл бұрын
BRILLIANT
@werewolf_13
@werewolf_13 4 жыл бұрын
Explanation was good. Thanks! Just would like to suggest a correction in the bubble sort algorithm .
@utkarshjha657
@utkarshjha657 Жыл бұрын
In the bubble sort if-expression, can we write :- if(compare(*(A+j), *(A+j+1) > 0) ?
@Praveenkumar4121994
@Praveenkumar4121994 8 жыл бұрын
tanx a lot!!! it was great help!!!!
@SuperSayiyajin
@SuperSayiyajin 5 жыл бұрын
Hi.Thanks for videos.I have a question. Is there any method or function to take array size? You typed Bubblesort( A,6 ); line. Can we use anything instead of 6?
@martianpirate9657
@martianpirate9657 4 жыл бұрын
11:30 --> qsort
@rationalisthuman3158
@rationalisthuman3158 9 жыл бұрын
why need of callback mechanism when we we can call the compare function directly @ 7:00
@billigerfusel
@billigerfusel 8 жыл бұрын
Because a library function don't know what your compare logic function is called.
@raj71441
@raj71441 7 жыл бұрын
I didn't understand why library function knows our compare function please tell.
@ognjen297
@ognjen297 2 жыл бұрын
God bless you !
@dumamageswarisitaraman9501
@dumamageswarisitaraman9501 4 жыл бұрын
Is it possible to apply pointer arithmetic operation with function pointer.
@sureshdharavath1191
@sureshdharavath1191 10 жыл бұрын
with out using the callback can't we call the compare function from the if condition so that we no need to pass the address from the calling function. Is there any problem in this ?
@VV-cy9gf
@VV-cy9gf 10 жыл бұрын
Using a function pointer instead of just calling a comparison function is more useful because then you can create many different comparison functions and still use that one sort function. This means you no longer have to have direct access to the implementation details of the sort function, thus helping to keep things cleaner and easier to see/manage.
@srujankumar1999
@srujankumar1999 8 жыл бұрын
+AMG POWER when we use function pointer...does it creates a slot for comparison function,above sort function on stack..for every comparision( comparing A[j],A[j+1] in a loop untill j
@yasserosama3405
@yasserosama3405 7 жыл бұрын
this explanation has solidified my understanding of function pointers and their use , thank you sir ! , please don't mind if I copy and paste your comment , as it would be new for people watching this video now , so they could easily see it and maybe help them understand like I did :)
@Arjunreddy-xi5ht
@Arjunreddy-xi5ht 7 жыл бұрын
AMG POWER Nice explanation..it helped me understand the actual use of a function pointer,ThankYou.
@bradmorgan60
@bradmorgan60 8 ай бұрын
Thank you so much.
@dickensowuor9091
@dickensowuor9091 Жыл бұрын
Good job
@tarunkumar7563
@tarunkumar7563 7 жыл бұрын
code that you write to explain the concept ,is the syntax is same in both c and cpp
@pvsrinivas100
@pvsrinivas100 10 жыл бұрын
very informational thank you.
@amarnathnayak1145
@amarnathnayak1145 8 жыл бұрын
can someone explain me the last program, where he pass "tom" string to called function but dereferenced it by 'name' while printing. why didn't he write *name?
@lifesmysteriesofficial
@lifesmysteriesofficial 5 жыл бұрын
4:42
@MrNams
@MrNams 7 жыл бұрын
thanks
@luqmanahmad7929
@luqmanahmad7929 11 жыл бұрын
Great yaar
@Kapil_Thakar
@Kapil_Thakar 10 жыл бұрын
great dear. useful.
@anshulsoni477
@anshulsoni477 10 жыл бұрын
I still dont get, it ! Using the flag would have been lot more easier, so why use a call back instead of that ?
@mycodeschool
@mycodeschool 10 жыл бұрын
Lets say you are designing a library function that would do something like sorting so anyone can just use your library function and sort. And you want to keep this sorting function generic , so data type can be anything. Then, how would you take the required information to sort from user of your library function? You cannot guess the comparison logic for a complex daya type. So, you would want to get the comparison logic too which can be passed as a function. So, in many cases when we are dealing with generic scenarios, function pointers make our life easier. It should be seen as a way to accept functionality as argument. So far, we knew that functions can accept only data, but now we know that even a function can be passed.
@anshulsoni477
@anshulsoni477 10 жыл бұрын
mycodeschool Cool got it, thanks
@akashpatel5547
@akashpatel5547 10 жыл бұрын
mycodeschool but i did not get it. it will good if you give small code example.
@anshulsoni477
@anshulsoni477 9 жыл бұрын
mycodeschool So wait I just realized this going over this answer that if I am passing compare for generic data type the function declaration for BubbleSort cant be void BubbleSort(int* A,int n, int* compare(int,int)); it has to be void BubbleSort(T* A,int n, int* compare(T,T));
@anshulsoni477
@anshulsoni477 9 жыл бұрын
Akash Patel According to what I understand this is an example struct vector { //Definition of struct friend bool operator>(vector& a,vector& b) { //Vector comparison logic here } }; template int compare(T a, T b) { //Same Logic } template void BubbleSort(T* a, int n, int(*compare)(T, T)) { //All the logic would stay the same //Except T temp; //instead of int temp; } int main() { //Declare an array of vectors; BubbleSort(A, 10, compare); }
@aakash4351
@aakash4351 7 жыл бұрын
math.h not working for me, when i try to use abs. Instead of it i have to use stdlib.h.
@muthusamy450
@muthusamy450 10 жыл бұрын
were is the link for event handling?? can you please provide the same.. thanks!! the vedio was very good :) :)
@mahimajangra3248
@mahimajangra3248 4 жыл бұрын
why we declare function variable with "(*ptr) ();" and use it as "ptr();" .... [without "*" ]
@jamestheking9816
@jamestheking9816 3 жыл бұрын
Because when you call any function, say add(), under the hood the CPU saves current address of where the program is, jumps to the *address* of the add() function, executes the statements in there, then jumps to the return address where the program left off. So, calling a function really just means “jump to the address of add() subroutine and execute those statements.” The C compiler knows when you declare a function pointer and use “*ptr”, you are dereferencing it, meaning you want to call the function. But as discussed, ptr() is *ptr() is the same thing, I.e. they mean the same thing
@nikhilanand984
@nikhilanand984 4 жыл бұрын
for compare function pointer in BubbleSort why didn't we passed the address of the compare function instead we directly passed the arguments.
@abdelrhmanahmed1378
@abdelrhmanahmed1378 4 жыл бұрын
Are this is what happen we do run time Polymorphism is just function pointer using vtable and vrpointers !?
@TON-vz3pe
@TON-vz3pe 4 жыл бұрын
So, basically function pointers are the same as method calling in java using public, private
@ijazmuhammed7822
@ijazmuhammed7822 3 жыл бұрын
Than you so much
@stevefrt9495
@stevefrt9495 8 жыл бұрын
Thanks you so much
@mrpossible5696
@mrpossible5696 5 жыл бұрын
12:50
@sudeshnaguharay5187
@sudeshnaguharay5187 Жыл бұрын
why in bubblesort func, the name of argument not changed to absolute_compare, still program is running fine?
@CHINMAYAM-p9i
@CHINMAYAM-p9i Жыл бұрын
yes i have the same doubt
Memory leak in C/C++
17:55
mycodeschool
Рет қаралды 246 М.
Function Pointers in C / C++
11:57
mycodeschool
Рет қаралды 439 М.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 36 МЛН
Function Pointers | C Programming Tutorial
18:31
Portfolio Courses
Рет қаралды 67 М.
Pointers as function arguments - call by reference
14:16
mycodeschool
Рет қаралды 489 М.
Function pointers, delegates and callbacks | Beginner friendly
26:03
Callback Functions in C Explained
13:26
Codeflash
Рет қаралды 52 М.
Pointers and multidimensional arrays
16:45
mycodeschool
Рет қаралды 245 М.
Function Pointers in C++
12:41
The Cherno
Рет қаралды 396 М.
Why Function Pointers are Awesome
11:11
Jacob Beningo
Рет қаралды 9 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 329 М.
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,5 МЛН
you will never ask about pointers again after watching this video
8:03