Junior — Middle
Have you had experience working with function pointers in programming?
sobes.tech AI
Answer from AI
Yes, I have experience working with function pointers in C/C++. They allow storing addresses of functions and calling them indirectly, which is useful for implementing callbacks, virtual function tables, or dynamic behavior selection.
Example of using a function pointer in C++:
#include <iostream>
void greet() {
std::cout << "Hello!" << std::endl;
}
void execute(void (*func)()) {
func();
}
int main() {
void (*funcPtr)() = &greet;
execute(funcPtr); // Outputs Hello!
return 0;
}
Here, funcPtr is a pointer to the greet function, which is passed to the execute function and called there.