C Programming Tutorial - Function Pointer in c programming language | Learn callbacks | With Example

preview_player
Показать описание
Topic discussed : 1) Concept of function pointer 2) Simple use case 3) Callback mechanism 4) Array of function pointers
Intro - Function pointer is similar to the variable pointer which points to the start address of the memory location where assigned function is stored .
A function is set of executable instructions which is stored in code segment of memory. If, the start address of these executable instruction where this function is stored is assigned to the function pointer. We can easily access (dereference) the function using function pointer.
Declaration, assignment and dereferencing has separately explained.
Assignment and dereferencing can be done in two ways.
Fact - Function pointers points to the code, not to the data.
- A function's name can also be used for the function start address.
#pointers

Use case 1 - Simple implementation of function pointer.
Declaration (Syntax) - can be done using return type of the function, then take function pointer name with * operator and take data type of the arguments.
Assignment - can be done in two ways with or without using & operator. As we know, & gives the start address. But, function name itself gives the address. So, we usually avoid using & operator.
Dereferencing - can also be done in two ways, depends on how is it assigned?
We have to use * operator, if & is used for assignment.
And it can done without using * operator, if & is not used for assignment.
Here, I have explained by taking a Add API which will be pointed by function pointer.
#functionpointers

Use case 2 - Callbacks
This is the main use case of function pointer, mostly in interrupt routines like DMA.
In callback mechanism, a function is passed to another function as an argument where it is called back.
#callbacks
Get the complete understanding of function pointers and its usage in c or c++ programming.

In interrupt routine, Application software programmer can write a user API which can be assigned to function pointer which will be executed by interrupt routine whenever interrupt occurs.
Application software programmer can set the user application using a driver API before enabling the interrupt.

Use case 3 - Array of function pointer
We can take function pointer array similar to the other arrays. And can use it for calling assigned functions with indexes 0, 1, 2 ... .
#arrayoffuntionpointer

Function pointers are similar to variable pointers which point to the start address of memory location where executable instructions are stored for function.

#functionpointer #pointer #cprogramming #programminginc #beginnertoadvance #pointerinc #pointersinc #callbackfunction #callback #functionpointerarray #bydubebox

programming in c,function pointer,pointers,c pointers,learn c programming,c function,c programming pointers,c++,c++ software,array c++,cpp c,functions in c programming,standard c++,pointers c++,use c,use of function pointer,callback function,array of function pointer,methods c++

=========================== Content of this video ===========================
0:00 Introduction
1:04 Topics to be discussed
1:33 Where does function pointer points to
3:10 Declaration , Assignment & Dereferencing
4:32 Simple use-case code
6:56 Callback code
10:04 Function pointer array code

Рекомендации по теме
Комментарии
Автор

Content wise its good. But one suggestion from my side... You are using too much unnessery animation in the video. Which is distracting and annoying. My suggestion is that make video as simple as you can. No animation is needed. Your content will speak for itself.

amitroy