SlideShare a Scribd company logo
3
#include<iostream.h>
#include<conio.h>
class employee
{
int age;
char name[20], post[20];
double salary;
public:
void getdata();
void putdata();
};
void employee::getdata()
{
cout<<"Name : ";
cin>>name;
cout<<"Age : ";
cin>>age;
cout<<"Post : ";
cin>>post;
cout<<"Salary : ";
cin>>salary;
}
void employee::putdata()
{
cout<<"Name : "<<name;
cout<<"nAge : "<<age;
cout<<"nPost : "<<post;
cout<<"nSalary : "<<salary;
}
int main()
{
int i;
clrscr();
employee emp[2];
for(i=1; i<2; i++)
{
cout<<"Get details :-n";
emp[i].getdata();
}
for(i=1; i<2; i++)
{
cout<<“nEmployee"<<i<<" :-n";
emp[i].putdata();
}
getch();
return 0;
}
Most read
11
 Example of array of object pointer:
#include<iostream.h>
#include<conio.h>
class abc
{
int code;
float price;
public:
void getdata(int a,int b)
{
code=a;
price=b;
}
void show()
{
cout<<"nCode:"<<code;
cout<<"nPrice:"<<price;
}
};
const int size=2;
int main()
{
clrscr();
abc *ptr=new abc[size];
abc *d=ptr;
int x,i;
float y;
for(i=1;i<size;i++)
{
cout<<"Input the value code & price:"<<i<<"n";
cin>>x>>y;
ptr->getdata(x,y);
ptr++;
}
for(i=1;i<size;i++)
{
cout<<"nitem:"<<i;
d->show();
d++;
}
getch();
return 0;
}
Most read
13
array of object pointer in c++
Most read
Array of Object & Pointer to Object
Made by: Patel Arpita V.
 Array is a collection of variable of same data types.
 Similarly, array of class objects means a collection of
objects of same types.
 Hence, an array having class type element is known as
array of object.
 syntax:
Class_name object_name [size];
#include<iostream.h>
#include<conio.h>
class employee
{
int age;
char name[20], post[20];
double salary;
public:
void getdata();
void putdata();
};
void employee::getdata()
{
cout<<"Name : ";
cin>>name;
cout<<"Age : ";
cin>>age;
cout<<"Post : ";
cin>>post;
cout<<"Salary : ";
cin>>salary;
}
void employee::putdata()
{
cout<<"Name : "<<name;
cout<<"nAge : "<<age;
cout<<"nPost : "<<post;
cout<<"nSalary : "<<salary;
}
int main()
{
int i;
clrscr();
employee emp[2];
for(i=1; i<2; i++)
{
cout<<"Get details :-n";
emp[i].getdata();
}
for(i=1; i<2; i++)
{
cout<<“nEmployee"<<i<<" :-n";
emp[i].putdata();
}
getch();
return 0;
}
array of object pointer in c++
 What is Pointer?
-Pointer means the variable that stores the address
of another variable.
 A pointer can point to an object created by class.
 Example: abc ob;
Here abc=class and ob=object of class abc.
 we can define pointer of type abc as below:
abc *ptr;
 Object pointers are useful in creating objects at run
time.
 We can also use an object pointer to access the public
members of class.
 We can access to member function of abc in two ways:
1)by using (.) dot operator
ex:- (*ptr).show();
2)by using () arrow operator
ex:- ptrshow();
 Example of Pointer to
object:
#include<iostream.h>
#include<conio.h>
class abc
{
int a,b,ADD;
public:
void getdata()
{
cout<<"Enter the values:" ;
cin>>a>>b;
}
void display()
{
ADD=a+b;
cout<<"Sum="<<ADD;
}
};
int main()
{
clrscr();
abc *ob;
(*ob).getdata();
ob->display();
getch();
return 0;
}
array of object pointer in c++
 Example:
abc *ptr =new abc[10];
here, abc=class
ptr=pointer
new=memory management operator
 Example of array of object pointer:
#include<iostream.h>
#include<conio.h>
class abc
{
int code;
float price;
public:
void getdata(int a,int b)
{
code=a;
price=b;
}
void show()
{
cout<<"nCode:"<<code;
cout<<"nPrice:"<<price;
}
};
const int size=2;
int main()
{
clrscr();
abc *ptr=new abc[size];
abc *d=ptr;
int x,i;
float y;
for(i=1;i<size;i++)
{
cout<<"Input the value code & price:"<<i<<"n";
cin>>x>>y;
ptr->getdata(x,y);
ptr++;
}
for(i=1;i<size;i++)
{
cout<<"nitem:"<<i;
d->show();
d++;
}
getch();
return 0;
}
array of object pointer in c++
array of object pointer in c++
array of object pointer in c++

More Related Content

What's hot (20)

9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
Nilesh Dalvi
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
Ritika Sharma
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
Kamal Acharya
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vishal Patil
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 
[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers
Muhammad Hammad Waseem
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Pranali Chaudhari
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
Kongu Engineering College, Perundurai, Erode
 
C functions
C functionsC functions
C functions
University of Potsdam
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Nilesh Dalvi
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
sneha2494
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Mohammed Sikander
 
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
Rabin BK
 

Similar to array of object pointer in c++ (20)

C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
ANUSUYA S
 
Array of objects.pptx
Array of objects.pptxArray of objects.pptx
Array of objects.pptx
RAGAVIC2
 
Unit 3
Unit 3Unit 3
Unit 3
S.S.B.T’s. College of Engineering & Technology
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
MuhammadAbubakar680442
 
polymorphism in c++ with Full Explanation.
polymorphism in c++ with Full Explanation.polymorphism in c++ with Full Explanation.
polymorphism in c++ with Full Explanation.
UdayGumre
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
Mufaddal Nullwala
 
Brief Summary Of C++
Brief Summary Of C++Brief Summary Of C++
Brief Summary Of C++
Haris Lye
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
Mauryasuraj98
 
Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan college
ahmed hmed
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
Dennis Chang
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
Getachew Ganfur
 
OOPS 22-23 (1).pptx
OOPS 22-23 (1).pptxOOPS 22-23 (1).pptx
OOPS 22-23 (1).pptx
SushmaGavaraskar
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notes
Rajiv Gupta
 
9781337102087 ppt ch12
9781337102087 ppt ch129781337102087 ppt ch12
9781337102087 ppt ch12
Terry Yoast
 
C++ computer language chapter 4 pointers.pdf
C++ computer language chapter 4 pointers.pdfC++ computer language chapter 4 pointers.pdf
C++ computer language chapter 4 pointers.pdf
birukh36
 
C96e1 session3 c++
C96e1 session3 c++C96e1 session3 c++
C96e1 session3 c++
Mukund Trivedi
 
Pointer and polymorphism
Pointer and polymorphismPointer and polymorphism
Pointer and polymorphism
SangeethaSasi1
 
oopm 2.pdf
oopm 2.pdfoopm 2.pdf
oopm 2.pdf
jayeshsoni49
 
Pointers_in_c.pptfffgfggdggffffrreeeggttr
Pointers_in_c.pptfffgfggdggffffrreeeggttrPointers_in_c.pptfffgfggdggffffrreeeggttr
Pointers_in_c.pptfffgfggdggffffrreeeggttr
MorfaSafi
 
C/C++ Pointers explanationwith different examples
C/C++ Pointers explanationwith different examplesC/C++ Pointers explanationwith different examples
C/C++ Pointers explanationwith different examples
ulhaq18
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
ANUSUYA S
 
Array of objects.pptx
Array of objects.pptxArray of objects.pptx
Array of objects.pptx
RAGAVIC2
 
polymorphism in c++ with Full Explanation.
polymorphism in c++ with Full Explanation.polymorphism in c++ with Full Explanation.
polymorphism in c++ with Full Explanation.
UdayGumre
 
Brief Summary Of C++
Brief Summary Of C++Brief Summary Of C++
Brief Summary Of C++
Haris Lye
 
Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan college
ahmed hmed
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
Dennis Chang
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
Getachew Ganfur
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notes
Rajiv Gupta
 
9781337102087 ppt ch12
9781337102087 ppt ch129781337102087 ppt ch12
9781337102087 ppt ch12
Terry Yoast
 
C++ computer language chapter 4 pointers.pdf
C++ computer language chapter 4 pointers.pdfC++ computer language chapter 4 pointers.pdf
C++ computer language chapter 4 pointers.pdf
birukh36
 
Pointer and polymorphism
Pointer and polymorphismPointer and polymorphism
Pointer and polymorphism
SangeethaSasi1
 
Pointers_in_c.pptfffgfggdggffffrreeeggttr
Pointers_in_c.pptfffgfggdggffffrreeeggttrPointers_in_c.pptfffgfggdggffffrreeeggttr
Pointers_in_c.pptfffgfggdggffffrreeeggttr
MorfaSafi
 
C/C++ Pointers explanationwith different examples
C/C++ Pointers explanationwith different examplesC/C++ Pointers explanationwith different examples
C/C++ Pointers explanationwith different examples
ulhaq18
 
Ad

Recently uploaded (20)

Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
Structure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS pptStructure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS ppt
Wahajch
 
Introduction to AI agent development with MCP
Introduction to AI agent development with MCPIntroduction to AI agent development with MCP
Introduction to AI agent development with MCP
Dori Waldman
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Flow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docxFlow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docx
rifka575530
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible PavementsPavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
ijfcstjournal
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
Airport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptxAirport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptx
BibekMedhi2
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptxDevelopment of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
aniket862935
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
Structure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS pptStructure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS ppt
Wahajch
 
Introduction to AI agent development with MCP
Introduction to AI agent development with MCPIntroduction to AI agent development with MCP
Introduction to AI agent development with MCP
Dori Waldman
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Flow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docxFlow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docx
rifka575530
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible PavementsPavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
ijfcstjournal
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
Airport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptxAirport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptx
BibekMedhi2
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptxDevelopment of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
aniket862935
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
Ad

array of object pointer in c++

  • 1. Array of Object & Pointer to Object Made by: Patel Arpita V.
  • 2.  Array is a collection of variable of same data types.  Similarly, array of class objects means a collection of objects of same types.  Hence, an array having class type element is known as array of object.  syntax: Class_name object_name [size];
  • 3. #include<iostream.h> #include<conio.h> class employee { int age; char name[20], post[20]; double salary; public: void getdata(); void putdata(); }; void employee::getdata() { cout<<"Name : "; cin>>name; cout<<"Age : "; cin>>age; cout<<"Post : "; cin>>post; cout<<"Salary : "; cin>>salary; } void employee::putdata() { cout<<"Name : "<<name; cout<<"nAge : "<<age; cout<<"nPost : "<<post; cout<<"nSalary : "<<salary; } int main() { int i; clrscr(); employee emp[2]; for(i=1; i<2; i++) { cout<<"Get details :-n"; emp[i].getdata(); } for(i=1; i<2; i++) { cout<<“nEmployee"<<i<<" :-n"; emp[i].putdata(); } getch(); return 0; }
  • 5.  What is Pointer? -Pointer means the variable that stores the address of another variable.
  • 6.  A pointer can point to an object created by class.  Example: abc ob; Here abc=class and ob=object of class abc.  we can define pointer of type abc as below: abc *ptr;  Object pointers are useful in creating objects at run time.
  • 7.  We can also use an object pointer to access the public members of class.  We can access to member function of abc in two ways: 1)by using (.) dot operator ex:- (*ptr).show(); 2)by using () arrow operator ex:- ptrshow();
  • 8.  Example of Pointer to object: #include<iostream.h> #include<conio.h> class abc { int a,b,ADD; public: void getdata() { cout<<"Enter the values:" ; cin>>a>>b; } void display() { ADD=a+b; cout<<"Sum="<<ADD; } }; int main() { clrscr(); abc *ob; (*ob).getdata(); ob->display(); getch(); return 0; }
  • 10.  Example: abc *ptr =new abc[10]; here, abc=class ptr=pointer new=memory management operator
  • 11.  Example of array of object pointer: #include<iostream.h> #include<conio.h> class abc { int code; float price; public: void getdata(int a,int b) { code=a; price=b; } void show() { cout<<"nCode:"<<code; cout<<"nPrice:"<<price; } }; const int size=2; int main() { clrscr(); abc *ptr=new abc[size]; abc *d=ptr; int x,i; float y; for(i=1;i<size;i++) { cout<<"Input the value code & price:"<<i<<"n"; cin>>x>>y; ptr->getdata(x,y); ptr++; } for(i=1;i<size;i++) { cout<<"nitem:"<<i; d->show(); d++; } getch(); return 0; }