SlideShare a Scribd company logo
2
Most read
8
Most read
11
Most read
I N T R O D U C T I O N
U S I N G T H I S F O R R E T U R N I N G V A L U E S
U S I N G T H I S F O R S P E C I F Y I N G M E M O R Y A D D R E S S
U S I N G T H I S F O R A C C E S S I N G D A T A M E M B E R S
This Pointer
Introduction
 Every member function of the class is born with the
pointer called this which points to the object with
which member function is associated.
 When a member function is invoked it comes into
existence with the value of this set to the address of
the object for which it is called
Using this for returning values
 This pointer can be used to return the values from
the member function.
 Since it points to the address of the object which
called the member function, we can return the object
by value with the help of this pointer
Sample Program
#include<iostream.h>
#include<conio.h>
class num
{
int a,b;
public:
num(int x, int y)
{
a=x;b=y;
}
void display()
{
cout<<"a="<<a<<" and
b="<<b<<endl;
}
num add(num);
};
num num:: add(num x)
{
a=a+x.a;
b=b+x.b;
return *this;
}
void main()
{
clrscr();
num obj1(1,2),obj2(3,4);
obj1.display();
obj2.display();
obj1.add(obj2);
obj1.display();
getch();
}
OUTPUT
Using this for specifying memory address
 This pointer is created automatically inside the
member function whenever the member function is
invoked by the object.
 It holds the memory address of the object so it can be
used to access the memory address of the object
Sample Program
#include<iostream.h>
#include<conio.h>
class num
{
int a;
public:
void displayAddress()
{
cout<<"The memory
address of the object is
"<<this<<endl;
}
};
void main()
{
clrscr();
num obj1,obj2;
obj1.displayAddress();
obj2.displayAddress();
getch();
}
OUTPUT
Using this pointer for accessing the data member
 This pointer can also be used to access the data
members inside the member function.
 It can be done with the help of arrow operator(->)
 Arrow operator is the combination of hyphen(-) and
greater than operator(>)
Sample Program
#include<iostream.h>
#include<conio.h>
class num
{
int a;
public:
void display()
{
this->a=89;
cout<<"a= "<<this->a
<<endl;
}
};
void main()
{
clrscr();
num obj1;
obj1.display();
getch();
}
OUTPUT

More Related Content

PPTX
Dynamic memory allocation in c++
PDF
Memory Management C++ (Peeling operator new() and delete())
PPTX
Function overloading and overriding
PPTX
[OOP - Lec 19] Static Member Functions
PPTX
Stream classes in C++
PPTX
Classes and objects
PPTX
Getters_And_Setters.pptx
PPTX
Abstract class in c++
Dynamic memory allocation in c++
Memory Management C++ (Peeling operator new() and delete())
Function overloading and overriding
[OOP - Lec 19] Static Member Functions
Stream classes in C++
Classes and objects
Getters_And_Setters.pptx
Abstract class in c++

What's hot (20)

PPS
Wrapper class
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
PPTX
07. Virtual Functions
PPTX
Member Function in C++
PPTX
classes and objects in C++
PPTX
Union in c language
PPTX
Constructor and destructor
PPTX
PPT
Class and object in C++
PDF
Constructor and Destructor
PPSX
Exception Handling
PPTX
PPTX
Data types in c++
PPT
friend function(c++)
PDF
Constructors and destructors
PPTX
Inheritance in c++
PPTX
Pointers in c++
PPTX
Chapter 05 classes and objects
PPTX
Structure in C language
PPTX
Pointer in C++
Wrapper class
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
07. Virtual Functions
Member Function in C++
classes and objects in C++
Union in c language
Constructor and destructor
Class and object in C++
Constructor and Destructor
Exception Handling
Data types in c++
friend function(c++)
Constructors and destructors
Inheritance in c++
Pointers in c++
Chapter 05 classes and objects
Structure in C language
Pointer in C++
Ad

Viewers also liked (9)

PPT
This pointer .17
PPTX
C++ Pointers
PPT
Intranet 47
PDF
Pointer in c++ part1
PPT
Unit 6 pointers
PPT
Multimedia formats
PPTX
Video formats
PPTX
What is an intranet
PPTX
File formats and its types
This pointer .17
C++ Pointers
Intranet 47
Pointer in c++ part1
Unit 6 pointers
Multimedia formats
Video formats
What is an intranet
File formats and its types
Ad

Similar to This pointer (20)

PPTX
class and objects
PPTX
Pointer to Member Function.pptx pointer in c++
PPT
DS Unit 6.ppt
PDF
Object Oriented Programming using C++ - Part 4
PPT
Unit vi(dsc++)
PPTX
pointers,virtual functions and polymorphism
PPT
Presentation
PPTX
this pointer this this this this this this
PPTX
Pointers,virtual functions and polymorphism cpp
PDF
polymorphism in c++ with Full Explanation.
PPT
w10 (1).ppt
PPTX
Object oriented programming slides for presentation
PPTX
CPP08 - Pointers
PDF
Pointer in C++_Somesh_Kumar_Dewangan_SSTC
PDF
Implementation of oop concept in c++
PPT
POINTERS IN C++ CBSE +2 COMPUTER SCIENCE
PPTX
ExamRevision_FinalSession_C++ notes.pptx
PPTX
pointers.pptx
PPTX
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
PDF
Pointers in Programming
class and objects
Pointer to Member Function.pptx pointer in c++
DS Unit 6.ppt
Object Oriented Programming using C++ - Part 4
Unit vi(dsc++)
pointers,virtual functions and polymorphism
Presentation
this pointer this this this this this this
Pointers,virtual functions and polymorphism cpp
polymorphism in c++ with Full Explanation.
w10 (1).ppt
Object oriented programming slides for presentation
CPP08 - Pointers
Pointer in C++_Somesh_Kumar_Dewangan_SSTC
Implementation of oop concept in c++
POINTERS IN C++ CBSE +2 COMPUTER SCIENCE
ExamRevision_FinalSession_C++ notes.pptx
pointers.pptx
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Pointers in Programming

More from Kamal Acharya (20)

PPTX
Programming the basic computer
PPTX
Computer Arithmetic
PPTX
Introduction to Computer Security
PPTX
Session and Cookies
PPTX
Functions in php
PPTX
Web forms in php
PPTX
Making decision and repeating in PHP
PPTX
Working with arrays in php
PPTX
Text and Numbers (Data Types)in PHP
PPTX
Introduction to PHP
PPTX
Capacity Planning of Data Warehousing
PPTX
Data Warehousing
PPTX
Search Engines
PPTX
Web Mining
PPTX
Information Privacy and Data Mining
PPTX
Cluster Analysis
PPTX
Association Analysis in Data Mining
PPTX
Classification techniques in data mining
PPTX
Data Preprocessing
PPTX
Introduction to Data Mining and Data Warehousing
Programming the basic computer
Computer Arithmetic
Introduction to Computer Security
Session and Cookies
Functions in php
Web forms in php
Making decision and repeating in PHP
Working with arrays in php
Text and Numbers (Data Types)in PHP
Introduction to PHP
Capacity Planning of Data Warehousing
Data Warehousing
Search Engines
Web Mining
Information Privacy and Data Mining
Cluster Analysis
Association Analysis in Data Mining
Classification techniques in data mining
Data Preprocessing
Introduction to Data Mining and Data Warehousing

Recently uploaded (20)

PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Business Ethics Teaching Materials for college
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Institutional Correction lecture only . . .
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
01-Introduction-to-Information-Management.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Classroom Observation Tools for Teachers
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
master seminar digital applications in india
PDF
Complications of Minimal Access Surgery at WLH
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Cell Types and Its function , kingdom of life
Business Ethics Teaching Materials for college
Module 4: Burden of Disease Tutorial Slides S2 2025
O5-L3 Freight Transport Ops (International) V1.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Pharma ospi slides which help in ospi learning
Institutional Correction lecture only . . .
FourierSeries-QuestionsWithAnswers(Part-A).pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
01-Introduction-to-Information-Management.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O7-L3 Supply Chain Operations - ICLT Program
Classroom Observation Tools for Teachers
PPH.pptx obstetrics and gynecology in nursing
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
master seminar digital applications in india
Complications of Minimal Access Surgery at WLH
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

This pointer

  • 1. I N T R O D U C T I O N U S I N G T H I S F O R R E T U R N I N G V A L U E S U S I N G T H I S F O R S P E C I F Y I N G M E M O R Y A D D R E S S U S I N G T H I S F O R A C C E S S I N G D A T A M E M B E R S This Pointer
  • 2. Introduction  Every member function of the class is born with the pointer called this which points to the object with which member function is associated.  When a member function is invoked it comes into existence with the value of this set to the address of the object for which it is called
  • 3. Using this for returning values  This pointer can be used to return the values from the member function.  Since it points to the address of the object which called the member function, we can return the object by value with the help of this pointer
  • 4. Sample Program #include<iostream.h> #include<conio.h> class num { int a,b; public: num(int x, int y) { a=x;b=y; } void display() { cout<<"a="<<a<<" and b="<<b<<endl; } num add(num); }; num num:: add(num x) { a=a+x.a; b=b+x.b; return *this; }
  • 7. Using this for specifying memory address  This pointer is created automatically inside the member function whenever the member function is invoked by the object.  It holds the memory address of the object so it can be used to access the memory address of the object
  • 8. Sample Program #include<iostream.h> #include<conio.h> class num { int a; public: void displayAddress() { cout<<"The memory address of the object is "<<this<<endl; } }; void main() { clrscr(); num obj1,obj2; obj1.displayAddress(); obj2.displayAddress(); getch(); }
  • 10. Using this pointer for accessing the data member  This pointer can also be used to access the data members inside the member function.  It can be done with the help of arrow operator(->)  Arrow operator is the combination of hyphen(-) and greater than operator(>)
  • 11. Sample Program #include<iostream.h> #include<conio.h> class num { int a; public: void display() { this->a=89; cout<<"a= "<<this->a <<endl; } }; void main() { clrscr(); num obj1; obj1.display(); getch(); }