In this blog, I’m explaining about Pointer  in c++

Pointer

Pointer is a variable that holds a memory address. This address is the location  of another object in memory.

Two special pointer operators are : * and &.

The & is unary operator that returns the memory address  of its operand. It is “ the  address of” operand. The * is complement of & it is also a unary operator and returns the value located at the address .

Example:

 

int main(array<System::String ^> ^args)
{
    int var= 10;
             int *p;
             p=&var;
             cout<<"Value of var variable";
             cout<<*p<<endl;
           Console::ReadKey(0);
    return 0;
}
Example of function pointer
int main(array<System::String ^> ^args)
{
    
     //example of function pointer
     int var;
     int (*ptest)(int)=test;
     var=ptest(3);
     cout<<var;
     ptest=test2;
     var=ptest(5);
     cout<<var;
      Console::ReadKey(0);
    return 0;
}

 

Leave Comment