Function Pointers | C Programming Tutorial

  Рет қаралды 69,858

Portfolio Courses

Portfolio Courses

Күн бұрын

Пікірлер: 141
@bettyswunghole3310
@bettyswunghole3310 2 ай бұрын
The idea of function pointers isn't terribly difficult...it's the syntax that's confusing. You explain it very well, though. This channel's a goldmine!
@naboulsikhalid7763
@naboulsikhalid7763 Жыл бұрын
this is my second time to watch this lesson, and the picture is more cleared. all what is explained has a sens and targeted the main core of pointer and its their use. You put all such effort to make it accessible and detailed for US, a work that has a GREAT MERIT. thank you
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're very welcome, thank you for leaving such positive and encouraging feedback! :-)
@sakib1108051
@sakib1108051 Жыл бұрын
The best function pointer video I have come across
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you for the positive feedback! :-)
@charlene2459
@charlene2459 7 ай бұрын
Loved this. I have been using structs as if they were classes, and function pointers as if they're class methods :'D
@lisandroiaffar4501
@lisandroiaffar4501 9 ай бұрын
This one video condenses so much. Examples are excellent templates. Brilliant content, thank you so much
@RakeshSolanki1
@RakeshSolanki1 Жыл бұрын
Everything about function pointers covered in one video. Great. Thanks.
@enzocalzone5298
@enzocalzone5298 11 ай бұрын
Callback functions in C make me appreciate virtual functions in C++ so much more :D
@PortfolioCourses
@PortfolioCourses 11 ай бұрын
Hahaha :-)
@aurinator
@aurinator 10 ай бұрын
Another great & simple explanation, thanks for creating it!
@Shivottmam
@Shivottmam 9 ай бұрын
This is the most beautifully and exceptionally well explained one of a kind video on a Function Pointers in C. Wow 🤩 amazing bravo 🙌 Thanks from India 🇮🇳.
@MorningNapalm
@MorningNapalm 4 ай бұрын
The function returning a function pointer was cool, I haven't seen that syntax before, but it makes total sense.
@FranksCreativeCorner
@FranksCreativeCorner Жыл бұрын
Great video! A few days ago I was researching for ways to introduce some sort of polymorphism in my generic linked list library when I stumbled upon function pointers. It completely blew my mind. I had not even the slightest idea you could do this with functions! It's crazy! Actually, I've been looking for this solution for quite a long time, but as I didn't know much of C or programming in general I didn't even know how to look for it. It wasn't until I started learning OOP fundamentals recently that I started getting hints of it. So, it's a particularly satisfying discoverment! Today I could finally start trying this out in my programs, but I'm having trouble understanding some things. In college we've been taught that a good programming practice is to declare functions, then define / implement them. In a similar manner, we've also learned from Abstract Data Types (I dunno the acronym in english, in my country is TDA) to declare all the interface's functions in the .h file, then define them all in a .c file. Without going much further, I was making a function "printData" that recieves a void pointer to some data and a pointer to a function to print that data according to its type (print_int if it's an integer, print_string and so on). I did an empty project and put everything only in the main.c file to be minimalistic. I first tried declaring all the functions above the main() function, then defining them below it, but it didn't work. Then I noticed that it does work when you just do it above the main function (declaration and implementation). My questions are: - Why is this? And, related to what I previously mentioned: - How should I do it when working with multi-file projects? It's also really plausible that I'm making a mistake so I'll double check, but ultimately my questions still stand.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I'm not sure why that wouldn't work to be honest, it should work. The only thing I can think of is that something was missing, like one of the function declarations or something like that. This video goes over how to create a library and split a program across multiple files: kzbin.info/www/bejne/rmnKpHt8d7xqsLs. After that video, this video about include guards may also be interesting: kzbin.info/www/bejne/pneUkJmOr5qthJI. :-)
@mr.dhillonkpt
@mr.dhillonkpt 2 ай бұрын
Nice Explaination Sir!! Keep the good work going.
@user-vs9uf3ny8z
@user-vs9uf3ny8z 6 ай бұрын
This is a great vid; have always been interested in making C do more dynamic things and this is a great illustration of how function pointers can accomplish that. Great explanation of these concepts
@poopoo-dk4hu
@poopoo-dk4hu 6 ай бұрын
I haven’t programmed in C in a two years and watched this out of curiosity but damn this video made it all click again
@bhagwatshinde648
@bhagwatshinde648 2 жыл бұрын
Amazing video. Crystal clear explanation
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome!
@ramakrishna4092
@ramakrishna4092 2 жыл бұрын
@@PortfolioCourses hi sir I am revising every topic from your lectures I have a doubt here in function pointers , here is my question what is the meaning of this line ( void *(*foo)(int *) ) I am confused after seeing this my doubt is after void * is there right can you pls explain that line it will be helpful to meee. Thank you so much sir love from India...
@festusnyabuto144
@festusnyabuto144 2 жыл бұрын
@@ramakrishna4092 that line declares a pointer, of a pointe to the function foo
@preciouslife1212
@preciouslife1212 Жыл бұрын
thank you so much. You have become my go to channel to learn c.❤❤❤❤❤❤
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're very welcome Robel, I'm so glad to hear this has become your go to channel for learning C! ❤️
@Danbotics
@Danbotics 10 ай бұрын
I found this really interesting but I’m left with a basic question - why would you do this? Even undergrad level programming courses do something similar and launch into explaining a complicated topic without first setting up why you might need to do this thing. It might be how my older brain is wired but I really respond better to a teaching process like this: * I want to do a thing (give a real world example of something that people will actually relate to) * Explain (or better, show) why what you’ve learned so far won’t be able to do this thing * Demonstrate how the new technique you’re about to teach solves this problem * Get into the details and teach the new topic I really do love the pacing and format of your videos (awesome work!) but I’m still struggling to connect it to a reason why this might be needed.
@vogesdg
@vogesdg 8 ай бұрын
And also explain the syntax will greatly improve he video.
@nikolaikalashnikov4253
@nikolaikalashnikov4253 Ай бұрын
Quote: " _Why would you do this_ ?": The simplest example would be that you're using another Utility do some "heavy lifting" for you: This is great, because you don't have to re-create all the functionality of that Utility yourself, so it speeds up development. However, if you call that Utility directly, then it becomes a "required dependency" and now it becomes an inconvenience for your Users, whereas if you call the Utility abstractly, then it's an "optional dependency": Which allows you to hook into many different Utilities that all perform similar work, which means that the User can choose which Utility to install. The "callbacks" he referred to might be a more intermediate level topic, while doing this to implement "backwards compatibility" might be a more advanced level topic ? Hopefully this helps ?
@silvioesilvanice
@silvioesilvanice Жыл бұрын
Thank you for this precious content. Im brazilian and I've following your videos
@vicsteiner
@vicsteiner 5 ай бұрын
One of the most interesting videos in the list up to now in my opinion. Learned a lot! I just do not totally agree with the idea that instructions are not data. That depends largely on the definition of data. The most precise I know is that data is defined as the lack of uniformity, in other words any perceivable difference (not meaning involved, data is not information) is data and instructions are perceivable differences therefore data. But you use instruction in a a different way then other bits of data. it still data though. That is the built of writing programs they are data that tell how to operate on data.
@oscarbarajas3610
@oscarbarajas3610 9 ай бұрын
Quite beautiful functionality. Thanks for sharing.
@jsmassinemassine1912
@jsmassinemassine1912 2 жыл бұрын
you did great job , thanks alot, from morocco
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome Jsmassine! 😀
@ValliNayagamChokkalingam
@ValliNayagamChokkalingam Жыл бұрын
Thanks for this amazing video! Crystal clear explanation!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome Valli-Nayagam! :-)
@pedronunes4072
@pedronunes4072 Жыл бұрын
Great content! I have one question if you may answer pls At 14:11 why are you calling the same function is_freezing with the same argument freeze_C, why are you repeating?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thanks Pedro! :-) I’m calling the function twice so I can test it twice with different user input values.
@pedronunes4072
@pedronunes4072 Жыл бұрын
@@PortfolioCourses Ooooh lol thanks!!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re welcome! :-)
@shroukalshoura5995
@shroukalshoura5995 Жыл бұрын
Really you are great , i tried to understand it from several videos but yours was the best ❤
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I'm glad the video helped you out Shrouk! :-)
@MorningNapalm
@MorningNapalm 4 ай бұрын
Without looking this up (it is really late), I think you don't need to say "(*function_pointer)(4);". I think you can just say "function_pointer(4);", since it is a variable which is a pointer, just like an array.
@moosyzeusy
@moosyzeusy 2 жыл бұрын
Great explanation! I appreciate this very much!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome! 🙂
@eyalshain5244
@eyalshain5244 8 ай бұрын
Bro you videos are fireeee! I think it will be good if you would do a vjdeo of you just building some sort of projects in c... for example implementing a vector in c, and you explain everything as you write it. Anyways.... thank you!
@cigmorfil4101
@cigmorfil4101 9 ай бұрын
08:45 why the elses ? When the return occurs it cannot get to the next statement which is the if.
@Barzi2001
@Barzi2001 10 ай бұрын
This channel is very good!
@anatoliishovah3108
@anatoliishovah3108 2 жыл бұрын
such an amazing explanation, thank you a lot!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're very welcome Anatolii! :-)
@PHXKHEEDGAMING
@PHXKHEEDGAMING 2 жыл бұрын
Omg. You just saved my ass. 😂😂😂😂😂I’m so happy it’s funny. The very first example you made was more than enough for me to understand what I needed 😂😂😂I love you man. 😭😭😭 You didn’t add the second way of declaring the function pointer tho. void (*function_pointer)(int) = &function; Or maybe you did I haven’t finished watching haha. But I’m definitely saved. On to my next hurdle. Thanks a lot
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
I'm glad to hear it helped you, and you're welcome! 🙂
@PHXKHEEDGAMING
@PHXKHEEDGAMING 2 жыл бұрын
@@PortfolioCourses I know I’ve been bugging since I found your channel. I’m sorry 😞.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Haha that's OK
@chaitanyadubakula
@chaitanyadubakula Жыл бұрын
At 12:37, is the freeze_check function call thing analogous to a, say, a lambda function in python or similar?
@bultvidxxxix9973
@bultvidxxxix9973 10 ай бұрын
No, not at all. A lambda function would be a function that you define when you use it. For example in C++ you could call the freeze_check function like this: is_freezing([](int temp){return (temp>273);}); In this case the function you pass to is_freezing is a lambda function. However, C doesn't have lambda functions, so you have to do it in two lines: bool freeze_K(int temp) {return (temp>273);} is_freezing(freeze_K);
@soumeshkundu8798
@soumeshkundu8798 10 ай бұрын
After seeing this video , why i am being so confident to build a high level language using c 🙃
@amabelarbi5538
@amabelarbi5538 Жыл бұрын
in 3:47 why there's no need to deference the pointer , in that case are'nt we gonna have the adresse ???
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Because it's a pointer to a function, and we're calling the function, we're not using a value like a pointer to a value like an int where we dereference the pointer to get the int value. In the case of pointers to functions we don't deference to call the function, and the 'reason' is just that it's different problems (accessing a value vs. calling a function) and ultimately it's because the creators of C made it that way. :-)
@umutabali
@umutabali 7 ай бұрын
Brilliant content, thank you so much
@PortfolioCourses
@PortfolioCourses 7 ай бұрын
You're very welcome, I'm glad you liked it! :-D
@vicsteiner
@vicsteiner 5 ай бұрын
Thanks for the video man! I do not understand though why we can add the address to the pointer without the &, is it related to the decay concept somehow? Also, the same doubt in why can we call add using the pointer without de-referencing it?
@MarcoAurelio-sv2tk
@MarcoAurelio-sv2tk 5 ай бұрын
C is like Linux: Linux: Everything is a file C: Everything is a pointer ahahah
@duds_sn
@duds_sn 10 ай бұрын
Holly! I've thought myself as a not so shitty programmer in C, having studied and developed somethings with effort but never heard anything near this concept. Amazing! I can see using it together with 2D arrays to dynamic select the desired function, working with indexes rather than If or Switch. Again, AMAZING
@MrTeen-ul7yc
@MrTeen-ul7yc Жыл бұрын
So is_freezing can be thought of as a higher order function right?
@AhmadAsmndr
@AhmadAsmndr Жыл бұрын
Your videos are amazing, thank you very much
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re very welcome, I’m glad you’re enjoying the videos! :-)
@johnnygarcia7297
@johnnygarcia7297 Жыл бұрын
I love your videos so much, this generation of programmers are really dumb and i feel like going back to the c/c++ programming days are what we truthly need for our understanding
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I’m glad you love the videos Johnny, and I think there is big value in going back to the basics with languages like C. :-)
@dominikbaricak9589
@dominikbaricak9589 Жыл бұрын
Study electrical engineering then. At deep level programming is just playing with electricity, logic gates and huge amount of physics and math. But understand all of this is not possible in one human life.
@johnnygarcia7297
@johnnygarcia7297 Жыл бұрын
@@dominikbaricak9589 i've done that, i build a drone with arduino and then upgrade it with some machine learning models so i had to switch the arduino into a rasparry pi and it made me fall in love even more im currently a fullstack dev but im planning on switching into AI real soon
@Redditard
@Redditard 11 ай бұрын
​@@dominikbaricak9589that's not the point here, but by your logic chemists etc should learn physics too
@koleso1v
@koleso1v 11 ай бұрын
I still do not understand why we can omit * when dereferencing function pointets.
@StackMemory0x00
@StackMemory0x00 8 ай бұрын
This is a great question and here is the answer: if you assign a function pointer using the syntax with & operator, you have to use the * dereference operator. Here is an example : function_pointers = &function in this case, you have to call the function by dereferencing it : (*function_pointers)(9) But if you assign a function pointers **without** &operator, you don't have to use the * dereference operator. function_pointers = function in this case, you can call it without * operator (function_pointers)(9) Pointers are tricky and take time to learn and master. Here is a playlist of Dr. Kevin's videos about pointers which I built over time: kzbin.info/www/bejne/aHinmot9areZhKc Watch these 9 videos many times until you feel comfortable with working with pointers Dr. Kevin's channel is the best place to learn C for beginners. I have been following his channel and learning from him since he had just a couple of thousand subscribers and I'm so happy to see the channel has almost 150k now. Best of luck.
@salmantechnologies282
@salmantechnologies282 2 жыл бұрын
Can we use the Arrow operator with the function pointer as we using it in pointer to structure
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Great question! :-) No... we use the arrow operator with pointers to structs to access the members of the struct. We can use the arrow operator with unions too. But functions don't have members, so we don't use the arrow operator with pointers to functions.
@salmantechnologies282
@salmantechnologies282 2 жыл бұрын
@@PortfolioCourses Thanks Sir I appreciate 👍
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome! :-)
@seankayll9017
@seankayll9017 11 ай бұрын
@@PortfolioCourses But can structs have members that are function pointers? Great videos btw. Very clear to understand.
@fancywaifu9821
@fancywaifu9821 2 жыл бұрын
I've always wondered this but whats the point of calling functions like this instead of it doing without pointers? Is it faster or more memory safe?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Great question! :-) We can use function pointers to create "callback functions": en.wikipedia.org/wiki/Callback_(computer_programming). What this means is that we can pass a function X TO another function Y as an argument, and then function Y can call function X at some point to do some work "later". One advantage of this is that we can "customize" the work that function Y does by supplying some specific "functionality" via the function argument we provide. That link goes into more detail with some examples. :-)
@fancywaifu9821
@fancywaifu9821 2 жыл бұрын
@@PortfolioCourses Thank you!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@fancywaifu9821 You're welcome! 🙂
@odissey2
@odissey2 11 ай бұрын
Using a function pointer slows code, as an extra dereferencing step is needed. It is not good for time-critical code, as it adds some 10-20 clocks
@muneerbasha1958
@muneerbasha1958 2 жыл бұрын
Best explanation sir
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you very much Muneer, I'm glad you enjoyed the explanation! :-)
@qqmayakashi
@qqmayakashi 11 ай бұрын
i learned pointers when I'm learning arduino and got fall in love with C so here am i learning pointers 😅
@yclept9
@yclept9 Жыл бұрын
How do you declare a function pointer x to a function that returns the function to call next? e.g. while(x=(*x)());
@ionguzun3952
@ionguzun3952 2 жыл бұрын
Thanks bro🙂😊
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You’re welcome!
@arminiuscherusci4410
@arminiuscherusci4410 8 ай бұрын
Great video
@PortfolioCourses
@PortfolioCourses 8 ай бұрын
I’m glad you liked it! :-)
@try-restart
@try-restart Жыл бұрын
Great video. Thank-you.
@ahmadibrahim3969
@ahmadibrahim3969 Жыл бұрын
Great video thanks a lot❤
@yahirgonzalez6679
@yahirgonzalez6679 11 ай бұрын
Thanks, man!
@jonathanmoore5619
@jonathanmoore5619 Жыл бұрын
Great video. Do function pointers dangle? Do we have to NULL them after use?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Great question Jonathan. I would say "not really". The idea of a dangling pointer is when we have a pointer variable that points to memory that is no longer valid. So if the pointer variable was pointing to memory on the heap, then we free that memory, but don't set the pointer to NULL, then the pointer is a "dangling pointer". With pointers to functions, the functions are not dynamically allocated, they exist in the compiled code and we point to them with function pointers. So we can't really have the function pointer point to memory that is "no longer" valid. It's possible to have a pointer that's pointing to an incorrect memory address like any other pointer I suppose, but that's really a different issue than a dangling pointer where we have a pointer that was is still pointing to memory that was at one point valid but no longer is. Hopefully this helps! :-)
@jonathanmoore5619
@jonathanmoore5619 Жыл бұрын
@@PortfolioCourses thanks, that does help. Appreciated.
@martinnyagah4313
@martinnyagah4313 Жыл бұрын
Hey, thank you so much for this awesome course! So I was just wondering, can we relate function pointers to call-back functions?
@martinnyagah4313
@martinnyagah4313 Жыл бұрын
Never mind. just found my answer @12:30
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Cool. :-)
@bhagwatshinde648
@bhagwatshinde648 2 жыл бұрын
Can you make video on structure pointer
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
That's a good idea maybe one day I'll make a video specifically on that. It is covered a little bit in some videos you might like already: kzbin.info/www/bejne/rWa7fmSEbM1_ncU
@bhagwatshinde648
@bhagwatshinde648 2 жыл бұрын
@@PortfolioCourses ok
@muneerbasha1958
@muneerbasha1958 2 жыл бұрын
Please make function pointer within a structure as member with examples
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Hmm, maybe I can do a video on that topic one day, thank you for the idea. :-)
@mnr_02
@mnr_02 Жыл бұрын
please say the name of the IDE or program you're using for coding and compiling, thanks in advance.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
In this video I'm using Xcode a Mac. :-)
@sparkybrit
@sparkybrit Жыл бұрын
Can select_operation have a parameter? If so, how would that be declared?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Yes, the parameter would go here: int (*select_operation(double parameter))(int, int) And we could provide an argument when we call select_operation... ... select_operation(2.5) ....
@yigitcoban9823
@yigitcoban9823 Жыл бұрын
I dont know my english is enough for describing but ı am going to try. İn this topic ı have a question about something. When we have created normal function and then have created a pointer function, if we equalize this two of them. We dont use brackets in normal function but on the other hand we created pointer function not in main and later then in main function if we wanna use this pointer function with another pointer function, we use brackets in pointer function. For example minute 3.25 in the video is the example of first part and minute 9.39 is the example of second part. Or is there any problem that we use brackets in normal function while we are using pointer function.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
So that second example at 9:39 is a function call to the function select_operation(). It's not assigning select_operation to the function pointer variable, it's assigning what select_operation() *returns* after it is called to the function pointer variable, and select_operation() is going to return a pointer to a function (subtract, multiply, etc.). Hopefully this helps! :-)
@yigitcoban9823
@yigitcoban9823 Жыл бұрын
@@PortfolioCourses wow thanks ✌️
@PortfolioCourses
@PortfolioCourses Жыл бұрын
@@yigitcoban9823 You're welcome! 🙂
@OrabyDance
@OrabyDance Жыл бұрын
@@PortfolioCourses I am literally in love with your videos and solid content... just a small question for the select_operation function at 7:26 what is the difference between what you did and writing this function as follows : int* select_operation() which is a function returning a pointer to integer which should be (subtract, multiply, etc.) i tried this and it is still working fine with no errors just wondering what is the difference? Thanks
@PortfolioCourses
@PortfolioCourses Жыл бұрын
@@OrabyDance int* select_operation() returns a pointer to an int, the function in the video returns a function which accepts two int parameters and returns an int. I believe you're not getting an error because in both cases, the function returns a pointer, and the rules around implicit pointer type conversion can allow for that, see this: stackoverflow.com/questions/52407576/can-you-assign-pointers-of-different-types-to-each-others.
@festusnyabuto144
@festusnyabuto144 2 жыл бұрын
Hello, which code editor are you using in the video?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Hi Festus, in this video I am using Xcode on a Mac. :-)
@MorningNapalm
@MorningNapalm 4 ай бұрын
Instead of "if (temperature
@windowsbuilderthegreat3121
@windowsbuilderthegreat3121 2 жыл бұрын
Does C have anonymous functions
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Anonymous functions are not officially part of the C standard, but gcc and clang both support features similar to anonymous functions: en.wikipedia.org/wiki/Anonymous_function#C_(non-standard_extension). Maybe one day I can cover these features. 🙂
@bultvidxxxix9973
@bultvidxxxix9973 10 ай бұрын
8:22 that part was ugly. First you don't need an else when the if part returns. The code behind the if will only be executed if and only if the condition for the if statement was evaluated to false. It's not just unnecessary characters to type, it also breaks the alignment of the statements. Secondly it should be a switch case anyways.
@looploop6612
@looploop6612 Жыл бұрын
hard to understand the syntax
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I agree it’s tricky looking. :-)
@fifaham
@fifaham Жыл бұрын
Nice
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thanks Firas! :-)
@maorberenstein2540
@maorberenstein2540 Жыл бұрын
Sanks men you pro
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome Maor! :-)
@awekeningbro1207
@awekeningbro1207 10 ай бұрын
it does not work. gave me compilation error: int add(int x, int y) { return x + y; } int sub(int x, int y) { return x - y; } int mult(int x, int y) { return x * y; } int div(int x, int y) { return x / y; } int *(select_operation())(int, int) { printf("select: "); printf("1. Add\t"); printf("2. Subtract "); printf("3. Multiply\t"); printf("4. Divide "); int n; scanf("%d ",&n); if(n == 1) return add; else if(n == 2) return sub; else if(n == 3) return mult; else if(n == 4) return div; else return add; } int main() { int (*operation)(int, int) = select_operation(); printf("enter two numbers: "); int x, y; scanf("%d %d ",&x,&y); operation(x,y); return 0; } got this error: warning: returning 'int (*)(int, int)' from a function with return type 'int' makes integer from pointer without a cast [-Wint-conversion] what's wrong?
@PortfolioCourses
@PortfolioCourses 10 ай бұрын
The code in the video is found here: github.com/portfoliocourses/c-example-code/blob/main/function_pointers.c. I notice the * is outside the brackets where you have select_operation() defined.
@takisbakalis
@takisbakalis 10 ай бұрын
i love you
@PortfolioCourses
@PortfolioCourses 10 ай бұрын
haha thanks! :-)
@syntactic_sugarboyy
@syntactic_sugarboyy Жыл бұрын
🖤🖤
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you Ekwueme! 🖤🖤
@stephanek9008
@stephanek9008 Жыл бұрын
I am still confused 😭
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Honestly function pointers are a pretty tough topic. Even if we understand the idea conceptually, the syntax is also tough to wrap our heads around. I think it's really important to have a good understanding of pointers before learning about function pointers, maybe this video can help a bit? :-) kzbin.info/www/bejne/aHinmot9areZhKc.
@franciscoarciganolasco6027
@franciscoarciganolasco6027 9 ай бұрын
Esto es joya
@overbored1337
@overbored1337 9 ай бұрын
Its a shame that they decided to use this wierd syntax in c
@arminiuscherusci4410
@arminiuscherusci4410 8 ай бұрын
What do you mean? It’s great
@overbored1337
@overbored1337 8 ай бұрын
@@arminiuscherusci4410 short answer c: typedef int (*func(int, int); cpp: using func = std::function;
@fannypack7705
@fannypack7705 8 ай бұрын
can you do a pointers for c++
@soumeshkundu8798
@soumeshkundu8798 10 ай бұрын
After seeing this video , why i am being so confident to build a high level language using c 🙃
Race Conditions Explained With An Example | C Programming Tutorial
12:11
Portfolio Courses
Рет қаралды 13 М.
struct Basics | C Programming Tutorial
24:44
Portfolio Courses
Рет қаралды 156 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
Introduction to Pointers | C Programming Tutorial
24:42
Portfolio Courses
Рет қаралды 122 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 336 М.
array vs &array Pointers Difference Explained | C Programming Tutorial
17:38
Function Pointers in C / C++
11:57
mycodeschool
Рет қаралды 440 М.
Void Pointers | C Programming Tutorial
12:44
Portfolio Courses
Рет қаралды 11 М.
you will never ask about pointers again after watching this video
8:03
int *p vs int* p Pointer Declarations | C Programming Tutorial
6:12
Portfolio Courses
Рет қаралды 141 М.
What are variadic functions (va_list) in C?
13:49
CodeVault
Рет қаралды 25 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН