Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
College aantekeningen

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

Beoordeling
-
Verkocht
-
Pagina's
22
Geüpload op
27-03-2026
Geschreven 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

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

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:

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
27 maart 2026
Aantal pagina's
22
Geschreven in
2025/2026
Type
College aantekeningen
Docent(en)
Manisha mam
Bevat
Alle colleges

Onderwerpen

€7,08
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kan je een ander document kiezen. Je kan het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
ashikaraipuriya

Maak kennis met de verkoper

Seller avatar
ashikaraipuriya Delhi public school
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
3 weken
Aantal volgers
0
Documenten
44
Laatst verkocht
-

0,0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Populaire documenten

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via Bancontact, iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo eenvoudig kan het zijn.”

Alisha Student

Veelgestelde vragen