Mastering C++
Function Pointers
Mastering PointersIn C++, you can actually pass a function to another function. This might sound strange at first, but it’s useful when you want to let the caller decide what action to take, without changing the code of the function doing the work.
To make that happen, we use something called a function pointer. It’s just a pointer that stores the address of a function, so we can call that function later on. This makes your code more flexible and customizable!
What is a Function Pointer?
A function pointer is a variable that holds the address of a function. Just like a regular pointer holds the address of a variable, a function pointer holds the address of some function.
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 21 more lessons in Mastering C++.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.