"this" pointer is different from a pointer to an object

Q. What is "this" pointer? Explain how is this is different from a pointer to an object?

 

Ans. This: This is variable that refers to the object that has called the member function. This variable is available in all the methods of the class. This is created automatically so we do not need to decide this variable.

 

Example

Class memory

{

Private Int rs;

Private Int paisa;

Public void set (int rs, Int paisa)

{

This. rs = rs;

This . paisa = paisa;

}

Public void set (Int rs, Int paisa)

{

Rs = rs;

Paisa = paisa;

}

*/

Note: If we comment out this x has been and put restriction on code y to execute, there will be default value in the field. if we create an object of this money class outside the money then, this pointer exists in that particular class only and a pointer to an object can exist in outside classes also. 

   Related Questions in Programming Languages

©TutorsGlobe All rights reserved 2022-2023.