function pointer syntax c++ code example
Example 1: c++ pointers
#include <iostream>
using namespace std;
int main () {
int var = 20;
int *ip;
ip = &var;
cout << "Value of var variable: ";
cout << var << endl;
cout << "Address stored in ip variable: ";
cout << ip << endl;
cout << "Value of *ip variable: ";
cout << *ip << endl;
return 0;
}
Example 2: pointer in c++
int a = 5;
cout << a;
int a = 5;
int *ab;
ab = &a;
cout << ab;
Example 3: what is this pointer in c++
Every object in C++ has access to its own address through an important pointer called this pointer.
The this pointer is an implicit parameter to all member functions.
Therefore, inside a member function,
this may be used to refer to the invoking object.
Friend functions do not have a this pointer,
because friends are not members of a class.
Only member functions have a this pointer.
Example 4: Function pointer C++
void one() { cout << "One\n"; }
void two() { cout << "Two\n"; }
int main()
{
void (*fptr)();
fptr = &one;
*fptr();
fptr = &two;
*fptr();
return 0;
}