Lecture 5: this Pointer Flashcards

1
Q

What is the difference between the memory allocation of the data members of an object of a class and its functions?

A
  • When a new object is created, each object has specific memory reserved for its data members
  • Functions of a class get memory that is shared by all objects of that class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does the function know which object of the class it has to act on?

A

• The address of the calling object is passed as a hidden argument to the function
The address is stored in the variable called this pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which has more precedence: dot operator or indirection operator?

A

Dot operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

2 cases in which this pointer may be required explicitly

A

When local variable and data member have same name

To return reference to calling object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly