blog

Home / DeveloperSection / Blogs / Pointer in c++

Pointer in c++

priyanka kushwaha2536 30-Jan-2015

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;
}

 


Updated 30-Jan-2015

Leave Comment

Comments

Liked By