Tuesday, March 15, 2016

What is this pointer/reference in C++/Java?

Let's explore it !

Let's understand it, through an example, Look at this example. 
Here the method returns the account corresponding to maximum balance. 
                               


So it clear from this example that, the method find() is returning an object corresponding to maximum balance.Two objects are passed to it, one is coming as a parameter and the other is made available to the method implicitly, as find() is invoked with it. Here the explicit object which is coming as parameter is 'a2' , copied in a local object 'ax' and with 'a1' the find method is invoked, hence it is available to the method implicitly.
As 'a1' represents implicit object, it's address is stored in a system pointer called 'this' pointer. To get this object we need to apply ' value at address operator'(*). as show in this slide.

How did you find this post.. Please reply...

No comments:

Post a Comment