what is the function of 'this' operator ?
Answers were Sorted based on User's Feedback
Answer / venkat
'this' is used to reffer current class variable
for example
class sample
{
int myvar=10;
void mymethod()
{
int myvar=20;
system.outprintln("The value of myvar is"+myvar)
system.outprintln("The value of myvar is"+this.myvar)
}
}
output :
20,10
| Is This Answer Correct ? | 39 Yes | 15 No |
Answer / bhawna
Basically "this" opertaor is a part of instance variable
hiding,when a local variable has the same name as an
instance variable,the local variables hides the instance
variables
| Is This Answer Correct ? | 21 Yes | 2 No |
Answer / walking legend
as we generally know a pointer is used to point to the
address of a particular variable and access its value.
Similarly,this is a pointer which always points to the
current object.
| Is This Answer Correct ? | 15 Yes | 3 No |
'this' pointer is created when you create an object with
dynamic memory allocation. 'this' pointer will be created at
the time of object creation.
It holds the current object's address.
'this' cannot be used inside the static or a friend functions.
| Is This Answer Correct ? | 14 Yes | 2 No |
Answer / sohaibx
it is an implicit pointer holding the address of current object.
| Is This Answer Correct ? | 5 Yes | 0 No |
Answer / sourav
Hi Venkat,
In your coding example the concept of this pointer is
fine, but can u pls tell me the where the object is getting
formed ?
| Is This Answer Correct ? | 7 Yes | 9 No |
What is design patterns in C++?
How to overload postfix operator in c++
What is data binding?
what is pointers
In the following declaration of main, "int main(int argc, char *argv[])", to what does argv[0] usually correspond? 1) The first argument passed into the program 2) The program name 3) You can't define main like that
What is late bound function call and early bound function call? Differentiate.
why we are declare the function in the abstract class even though we are declaring it in Derived class?
what is ltti
WHY FUCTION OVERLOADING DOSENOT RETURN A RETEN TYPE
Name an advantage of linked list over array?
how do you handle yourself when you feel the wald is aganist you
What is polymorphism and types?