Callback Functions in C Explained

Sdílet
Vložit
  • čas přidán 4. 07. 2024
  • This video explains callback functions and shows how to implement them in C.
    At the start, basics of callback functions are explained. Next, an example is shown that demonstrates how to easily implement callback functions in C. Lastly, an example is shown on how to use the qsort() function that is inside the C standard library.
    Code:
    github.com/CodeflashVideos/ca...
    Chapters:
    00:00 Introduction
    00:18 Basics of Callback Functions
    02:05 First Example: Implementation, Passing and Calling Callback Functions
    05:58 First Example: A Simplification of the Function Pointer Syntax by Using a typedef
    07:03 Second Example: An Explanation of the qsort() Function Which Uses Callback Functions
    08:58 Second Example: An Implementation of a Comparison Callback Function and It's Usage for the qsort() Function
    13:15 Outro
    LIKE | COMMENT | SHARE | SUBSCRIBE
  • Věda a technologie

Komentáře • 33

  • @xaiga29
    @xaiga29 Před 2 lety +15

    My question was answered within the first 40 seconds of the video, "What is a callback function?" Answer: "A callback function is a function that is passed to another function as an argument." Good Stuff!

  • @jasnarmstrng
    @jasnarmstrng Před 4 měsíci +2

    Clear and straight to the point. Thanks.

  • @bizzy423
    @bizzy423 Před 3 lety +4

    Thank You for going more in depth in your example using qsort. Look forward to your "C" videos!

  • @netsweemji
    @netsweemji Před 2 lety +5

    You explained it well .it is very good and easy to understand.

  • @alikemalaldogan2492
    @alikemalaldogan2492 Před 8 měsíci

    I really liked the content. At these days it is very hard to find a deeply and simply videos. Thanks

  • @ImmortalBest
    @ImmortalBest Před 2 lety +5

    найс инглиш, мой славянский друг )

  • @dhruvandangar8005
    @dhruvandangar8005 Před 2 lety +3

    very informative.
    that type of deep knowledge content we need.
    please make more of these types of videos.

  • @slavago1266
    @slavago1266 Před 2 lety +1

    Wow, I understand everything you explained in the video so easily! Thank you very much!

  • @shadabpundeer3105
    @shadabpundeer3105 Před 8 měsíci

    Easy to understand. We can directly call the callback function just like a normal routine. Why we made them function pointer?
    int main(){
    add(5,5):
    }

  • @moizkhan132
    @moizkhan132 Před 3 lety +1

    This video is great, You cleared my concept of callback and function pointer, Thanks a lot

  • @almnetx
    @almnetx Před 2 lety

    Best Callback Explanation Ever! Thanks my friend, GBY!

  • @JamesEggleston
    @JamesEggleston Před 2 lety

    That’s was such a good explanation, thanks!!

  • @shrikantvaishnav1077
    @shrikantvaishnav1077 Před 3 lety

    Short and precise description 👍👍👍

  • @redmundperrz7234
    @redmundperrz7234 Před 3 měsíci

    Very good explanation and sample of function pointer

  • @christopherlabisch621
    @christopherlabisch621 Před rokem +1

    Thank you very much. Very precise and to the point.
    I have a question. Is it possible to implement asynchronous callback functions in C?

  • @yadniksn6657
    @yadniksn6657 Před 3 lety

    Nice explanation.
    Plz add more vdos on this topic like sending struct pointer and many more.🙏🙏

  • @atharwaadawdakar4144
    @atharwaadawdakar4144 Před 3 lety +1

    Great explanation !!

  • @austinbaccus
    @austinbaccus Před 3 lety +1

    Awesome video. Thank you for the explanation! :)

    • @codeflash6896
      @codeflash6896  Před 3 lety +1

      Hey, thanks for your input.
      Please keep in mind that the video is about implementing callback functions in C while you are talking about C++. C doesn't support lambda expressions.

  • @justdoingodswork
    @justdoingodswork Před rokem

    Thank for this video, really helped me.

  • @MegaMicraman
    @MegaMicraman Před 8 měsíci

    Very good.

  • @coachremmy
    @coachremmy Před 3 lety

    great video

  • @fokusdesain9521
    @fokusdesain9521 Před 2 měsíci

    good bro

  • @juanalbertofalconquezada3738

    Thaks a lot!

  • @NeverGiveUp_oo7
    @NeverGiveUp_oo7 Před rokem

    Can you implement asynchronous call back function?

  • @dahlia2631
    @dahlia2631 Před 2 lety

    Could you please share video with information regarding how callback function is different from goto ?

  • @cyberspider78910
    @cyberspider78910 Před 2 lety

    I am clearing my own mind. Just correct me if I am wrong :
    "Using compar as the way it is defined (i.e. int compar (const void *p1, const void* p2); allows a custom comparison function even for objects derived from a class via type casting in compar function same as the way you have done by casting those void* pointers to int* pointer. "
    If I understood above correctly, I think I have understood the utility of call back functions correctly. Please verify my understanding and oblige.

  • @ubaidarshad
    @ubaidarshad Před 3 měsíci

    Thanx 😅

  • @mehulshah9027
    @mehulshah9027 Před 3 lety +4

    everyone explains what you explained...but give real time example of synchronous and asynchronous callback functions

  • @yonatanelizarov6747
    @yonatanelizarov6747 Před rokem

    So callback functions are like interrupts?

    • @codeflash6896
      @codeflash6896  Před rokem

      They are more like interrupt service routines.

    • @yonatanelizarov6747
      @yonatanelizarov6747 Před rokem

      @@codeflash6896 Why don't use function call from inside the function? What added value we get from putting function as argument?

    • @codeflash6896
      @codeflash6896  Před rokem +1

      Because different callback functions can be called from a single "main" function.
      By providing the callback function as an argument to a "main" function, the code is more generic since only this "main" function is needed to call different callback functions within it.
      The alternative would be to have multiple different "main" functions that each call their hardcoded callback function. This creates code duplication.