Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Pointers in OOP (C++) – Complete Notes | Concepts, Syntax, Examples, Pointer to Objects, this Pointer | Unit V

Rating
-
Sold
-
Pages
22
Uploaded on
27-03-2026
Written in
2025/2026

Master Pointers in Object-Oriented Programming (C++) with these complete Unit V notes. This document covers all important concepts including pointer basics, pointer to objects, dynamic memory allocation, and the this pointer with clear syntax and examples. Perfect for B.Tech, BCA, MCA, and competitive exam students, these notes are written in an easy-to-understand format with diagrams and practical coding examples. ️ Covers theory + examples ️ Exam-oriented explanations ️ Clean handwritten/typed structured content ️ Ideal for revision and quick learning Boost your understanding and score high in exams

Show more Read less
Institution
Course

Content preview

UNIT-5
Pointers and file concept:
Pointer Overview:

The symbol of an address is represented by a pointer. In addition to creating and
modifying dynamic data structures, they allow programs to emulate call-by-reference.
One of the principal applications of pointers is iterating through the components of
arrays or other data structures. The pointer variable that refers to the same data type as
the variable you're dealing with has the address of that variable set to it (such as an int
or string).
Syntax
• datatype *var_name;
• int *ptr; // ptr can point to an address which holds int data




Pointers to object:
A pointer is a variable that stores the memory address of another variable (or object) as its value.
A pointer aims to point to a data type which may be int, character, double, etc.
Pointers to objects aim to make a pointer that can access the object, not the variables.
There are two approaches by which you can access an object. One is directly and the other is by
using a pointer to an object in C++.
• syntax:
classname*pointertoobject;

For storing the address of an object into a pointer use the following syntax:
pointertoobject=&objectname;
Example 1. In the below example, a simple class named My_Class is created. An object of the
class is defined as named object. Here a pointer is also defined named p. In the program given
below program, it is shown how can we access the object directly and how can we use the
pointer to access the object directly.

// Example using an object pointer.

#include <iostream>
using namespace std;

class My_Class {
int num;

,public:
void set_number(int value) {num = value;}
void show_number();
};

void My_Class::show_number()
{
cout << num << "\n";
}

int main()
{
My_Class object, *p; // an object is declared and a pointer to it

object.set_number(1); // object is accessed directly
object.show_number();

p = &object; // the address of the object is assigned to p
p->show_number(); // object is accessed using the pointer

return 0;
}



Output:
1
1
// Increment and decrement are done of an object pointer.
#include <iostream>
using namespace std;

class My_Class {
int num;
public:
void set_number(int val) {num = val;}
void show_number();
};

void My_Class::show_number()
{
cout << num << "\n";
}

int main()
{
My_Class object[2], *p;

object[0].set_number(10); // objects is accessed directly
object[1].set_number(20);

p = &object[0]; // the pointer is obtained to the first element
p->show_number(); // value of object[0] is shown using pointer

p++; // advance to the next object
p->show_number(); // show value of object[1] is shown using the pointer

, p--; // retreat to previous object
p->show_number(); // again value of object[0] is shown

return 0;
}



Output:
10
20
10

Example 2. In the below example, we used a pointer to an object and an arrow operator.
#include<iostream>
using namespace std;

class Complex{
int real, imaginary;
public:
void get_Data(){
cout<<"Here the real part is "<< real<<endl;
cout<<"Here the imaginary part is "<< imaginary<<endl;
}

void set_Data(int x, int y){
real = x;
imaginary = y;
}

};
int main(){
Complex *ptr = new Complex;
ptr->set_Data(1, 54);
ptr->get_Data();

// Array of Objects
Complex *ptr1 = new Complex[4];
ptr1->set_Data(1, 4);
ptr1->get_Data();
return 0;
}



Output:
Here the real part is 1
Here the imaginary part is 54
Here the real part is 1
Here the imaginary part is 4


This pointer:

Written for

Institution
Course

Document information

Uploaded on
March 27, 2026
Number of pages
22
Written in
2025/2026
Type
Class notes
Professor(s)
Manisha mam
Contains
All classes

Subjects

$7.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
ashikaraipuriya

Get to know the seller

Seller avatar
ashikaraipuriya Delhi public school
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 weeks
Number of followers
0
Documents
44
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions