what is this pointer 3f explain with an example

Solutions on MaxInterview for what is this pointer 3f explain with an example by the best coders in the world

showing results for - "what is this pointer 3f explain with an example "
Fernando
06 Jul 2018
1Every object in C++ has access to its own address through an important pointer called this pointer.
2The this pointer is an implicit parameter to all member functions.
3Therefore, inside a member function, this may be used to refer to the invoking object.
4
5Example:
6#include <iostream>
7using namespace std;
8class Demo {
9private:
10  int num;
11  char ch;
12public:
13  void setMyValues(int num, char ch){
14    this->num =num;
15    this->ch=ch;
16  }
17  void displayMyValues(){
18    cout<<num<<endl;
19    cout<<ch;
20  }
21};
22int main(){
23  Demo obj;
24  obj.setMyValues(100, 'A');
25  obj.displayMyValues();
26  return 0;
27}
28