Home > DeveloperSection > Blogs > Pointer in c++

Pointer in c


Visual C++ .NET 
Ratings:
0 Comment(s)
 588  View(s)
Rate this:

Pointer in c++

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;

}

 


Don't want to miss updates? Please click the below button!

Follow MindStick