Rédigé par des étudiants ayant réussi Disponible immédiatement après paiement Lire en ligne ou en PDF Mauvais document ? Échangez-le gratuitement 4,6 TrustPilot
logo-home
Notes de cours

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

Note
-
Vendu
-
Pages
22
Publié le
27-03-2026
Écrit en
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

Montrer plus Lire moins
Établissement
Cours

Aperçu du contenu

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:

École, étude et sujet

Établissement
Cours

Infos sur le Document

Publié le
27 mars 2026
Nombre de pages
22
Écrit en
2025/2026
Type
Notes de cours
Professeur(s)
Manisha mam
Contient
Toutes les classes

Sujets

€7,11
Accéder à l'intégralité du document:

Mauvais document ? Échangez-le gratuitement Dans les 14 jours suivant votre achat et avant le téléchargement, vous pouvez choisir un autre document. Vous pouvez simplement dépenser le montant à nouveau.
Rédigé par des étudiants ayant réussi
Disponible immédiatement après paiement
Lire en ligne ou en PDF

Faites connaissance avec le vendeur
Seller avatar
ashikaraipuriya

Faites connaissance avec le vendeur

Seller avatar
ashikaraipuriya Delhi public school
S'abonner Vous devez être connecté afin de suivre les étudiants ou les cours
Vendu
-
Membre depuis
3 semaines
Nombre de followers
0
Documents
44
Dernière vente
-

0,0

0 revues

5
0
4
0
3
0
2
0
1
0

Documents populaires

Récemment consulté par vous

Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Foire aux questions