can we return pointer to function in cpp code example
Example 1: pointers to pointers in cpp
#include <iostream>
using namespace std;
int main () {
int var;
int *ptr;
int **pptr;
var = 3000;
ptr = &var;
pptr = &ptr;
cout << "Value of var :" << var << endl;
cout << "Value available at *ptr :" << *ptr << endl;
cout << "Value available at **pptr :" << **pptr << endl;
return 0;
}
Example 2: c++ function return pointer to itself
struct func_wrap
{
using f_t = func_wrap(*)();
f_t func;
f_t operator()() const noexcept { return func; }
operator f_t() const noexcept { return func; }
};
using func_t = func_wrap(*)();
func_wrap foo() { return func_wrap{foo}; }
func_t bar() { return foo(); }
func_t buz() { return foo()(); }
struct function
{
function operator()() const noexcept
{
return function();
}
};
function foo(int) { return function(); }
function bar(int) { return function()(); }
function buz(int) { return function()()(); }