Home / Programs / Facts about function pointers
🚀 Programming Example

Facts about function pointers

👁 927 Views
💻 Practical Program
📘 Step Learning
some interesting facts about function pointers

💻 Program Code

#include <stdio.h>
// A normal function with an int parameter
// and void return type
void fun(int a)
{
    printf("Value of a is %d\n", a);
}
 
int main()
{ 
    void (*fun_ptr)(int) = fun;  // & removed
 
    fun_ptr(10);  // * removed
 
    return 0;
}

                        

🖥 Program Output

Value of a is 10
                            

📘 Explanation

some interesting facts about function pointers

1. Unlike normal pointers, a function pointer points to code, not data. Typically a function pointer stores the start of the executable code.

2. Unlike normal pointers, we do not allocate de-allocate memory using function pointers.

3. A function?s name can also be used to get functions? address. For example, in the below program, we have removed address operator ?&? in assignment. We have also changed function call by removing *, the program still works.

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.