Understanding and Using Function Pointers in C

preview_player
Показать описание
---

Understanding and Using Function Pointers in C // A lot of my students struggle with function pointers. Mostly, they have a hard time reading the declarations. So, hopefully, this video will help make things a bit clearer.



***

Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.

About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.

More about me and what I do:

To Support the Channel:
+ like, subscribe, spread the word

Want me to review your code?

You can also find more info about code reviews here.
Рекомендации по теме
Комментарии
Автор

I wish I had teachers like you in college.

sjittube
Автор

I prefer to typedef the function declaration, like this:

typedef int operation_func(int, int);

Then declare a function pointer variable with

operation_func *op;

That way you avoid the awkward parenthesis syntax and you don't hide that fact that 'op' is a pointer inside the typedef.

sverkeren
Автор

This should call "How to show mastery in a lesson". Thanks for the video.

ulysses_grant
Автор

Watching this a year later, and I must say this was really clean. Especially using the typedef. Thank you for this.

TheChemicalBassist
Автор

The first time I watched this video, I couldn't comprehend the content. After going back to basics on pointers and function calls, this was very nicely explained. The typedef part makes a LOT of sense seeing the mess created by function pointers as arguments. Thanks a lot professor!

akhileshb_
Автор

Fantastic video! You explain function pointers so clearly and break it down. Probably saved me 30 minutes of googling :)

nathanbrown
Автор

Honestly comming from C++ I always had trouble understanding C style function pointers but seeing them like this makes it so much clearer and less intimidating, thank you!

levidekoning
Автор

Ya i was reading the man page for pthread_create and one of the parameters is:
void *(*start_routine) (void *)
I had no idea what this was at first.
From your video I know now that it is a pointer to a function (start_routine) that takes void * as a parameter and returns a void *.

seal
Автор

You sir are amazing. In 4 minutes you easily explained a function pointer as well as a typedef with a func pointer. Subbed and liked. Bravo.

TheDa
Автор

This channel is way too underrated. Thank you so much again! Professor Sorber, you've helped me a ton in my undergrad and now again in grad school!

grevierx
Автор

1. I tried this declaration:
void (*fun_ptr)(void);

2. At assignment:
fun_ptr= &task1;
fun_ptr = &task2;


3. Then at call location:
if(lock){fun_ptr();}



worked !

PerchEagle
Автор

Thanks for the video! It was very helpful! My first exposure to "pointers to functions" was in C++ and the syntax created a long-lasting mental block for me. lol Thanks for posting!

TheCocoaDaddy
Автор

use of typedef for function pointer is Highlight for me. Thanks Jacob.
Before watching this video - Use of typedef is to create give data type a new name. mostly used with char, int, float, double, struct, union.
After watching this video - we can use typedef for function pointer as well.

Request for everyone if they have any new prospective to look at typedef then please comment for better understanding of everyone 👍.

pipaliyakuldeep
Автор

dude, where have oyu been all my life. your way of teaching is the best for any C tutorial i've seen

GrandNecro
Автор

This was concise and explained well. Thank you!

stephenjames
Автор

THANK YOU!! Crystal clear explanation
Don't know how could you pull it off in less than 4 min but i totally appreciate it

ahmedmetwaly
Автор

I watched the chernos video first bc I though 11 min > 4 min.

This actually explains what he said and more.

You are doing an awesome job👍

thevd
Автор

I've never seen someone explain how function pointers work in a way that's easy to follow and quick.

fabmilan_
Автор

Excelente explicação. Congratulations from Brazil.

Olavotemrazaodenovo
Автор

Over 5 years later and this is still a great video.

papasmurf