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 |
why to use template classes in c++?
What language is oop?
#include <stdio.h> #include <alloc.h> #include <stdlib.h> #include <conio.h> void insert(struct btreenode **, int); void inorder(struct btreenode *); struct btreenode { struct btreenode *leftchild; struct btreenode *rightchild; int data; }; main() { struct btreenode *bt; bt=(struct btreenode *)NULL; int req,i=1,num; clrscr(); printf("Enter number of nodes"); scanf("%d",&req); while(i<=req) { printf("Enter element"); scanf("%d",&num); insert(&bt,num); i++; } inorder(bt); } void insert(struct btreenode **sr, int num) { if(*sr==NULL) { *sr=(struct btreenode *)malloc (sizeof(struct btreenode)); (*sr)->leftchild=(struct btreenode *)NULL; (*sr)->rightchild=(struct btreenode *)NULL; (*sr)->data=num; return; } else { if(num < (*sr)->data) insert(&(*sr)->leftchild,num); else insert(&(*sr)->rightchild,num); } return; } void inorder(struct btreenode *sr) { if(sr!=(struct btreenode *)NULL) { inorder(sr->leftchild); printf("\n %d",sr->data); inorder(sr->rightchild); } else return; } please Modify the given program and add two methods for post order and pre order traversals.
What is the point of polymorphism?
what uses of c++ language?
What is this pointer in oop?
When a private constructer is being inherited from one class to another class and when the object is instantiated is the space reserved for this private variable in the memory??
Can we override main method?
if u write a class do u write Assignment operator and copy constructor
difference between class and object
10 Answers Chandan, IBM, Magic Soft,
How do you explain polymorphism?
what is new modifier in C#