SlideShare a Scribd company logo
ARRAY OF POINTER
SUBMITTED BY:
IRUM
ABDULLAH
SUBMITTED TO:
MISS ZAINAB
WHAT IS ARRAY OF POINTER?
An array of pointer is an array in which eachelement is a pointer. Each
element in the array can store a memory address. The array can store
the memory addresses of different objects of data.
FOR EXAMPLE
#include<iostream.h>
#include<conio.h>
Void main()
{
clrscr()
Int*ptr[3],a,b,c;
Int i;
Ptr[0]=&a;
Ptr[1]=&b;
Ptr[2]=&c;
cout<<“enter three integer:”<<endl;
cin>>a>>b>>c;
cout<<“you enter the following values:n”;
for(i=0;i<3;i++)
cout<<*ptr[i]<<endl;
getch();
}
HOW ABOVE EXAMPLE WORK?
The above program declares an array of integer pointer and three
integer variables. Each element of pointer array refers to different
variable. The program input values to the variables and display them
using array of pointer.
Ptr[0] Ptr[1] Ptr[2]
a b c
ARITHMETIC OPERATOR ON POINTER
ARITHMETIC OPERATION ON POINTER
 Indirection (*): This operator is used to get the value from the pointed
address.
 Reference operator( &): This operator is used get the address of the
variable or pointer.
 Assignment ( =): You can assign the value to the pointer or value to the
address which is pointed by the pointer.
 Incrementing: You can add integer value to the pointer to point the
different memory location.
 Decrementing: You can subtract the integer value from the pointer to
point the different memory location.
 Comparison :This operation is valid only between two pointers that point
to the same array.
DECREMENT A POINTER
The same considerations apply to decrementing a
pointer, which decreases its value by the number of
bytes of its data type as shown below
PROGRAM BY USING DECREMENT ON A POINTER
#include <iostream>
using namespace std;
const int MAX = 3;
int main ()
{
int var[MAX] = {10, 100, 200};
int *ptr; // let us have address of the last element in pointer.
ptr = &var[MAX-1];
for (int i = MAX; i > 0; i--)
{
cout << "Address of var[" << i << "] = ";
cout << ptr << endl; cout << "Value of var[" << i << "] = ";
cout << *ptr << endl; // point to the previous location ptr--;
}
return 0;
}
INCREMENT A POINTER
We prefer using a pointer in our program instead of an array because the
variable pointer can be incremented, unlike the array name which
cannot be incremented because it is a constant pointer. The following
program increments the variable pointer to access each succeeding
element of the array −
PROGRAME USING INCREMENT OPERATOR
#include <iostream>
using namespace std;
const int MAX = 3;
int main ()
{
int var[MAX] = {10, 100, 200};
int *ptr; // let us have array address in pointer.
ptr = var;
for (int i = 0; i < MAX; i++)
{
cout << "Address of var[" << i << "] = ";
cout << *ptr << endl;
cout << "Value of var[" << i << "] = ";
cout << *ptr << endl; // point to the next location
ptr++;
}
return 0;
}
COMPARISON ON POINTER
 Pointers may be compared by using relational operators, such as ==, <,
and >. If p1 and p2 point to variables that are related to each other, such
as elements of the same array, then p1 and p2 can be meaningfully
compared.
 The following program modifies the previous example one by
incrementing the variable pointer so long as the address to which it
points is either less than or equal to the address of the last element of
the array, which is &var[MAX - 1] −
PROGRAM BY USING COMPARISON ON A POINTER
#include <iostream>
using namespace std;
const int MAX = 3;
int main ()
{
int var[MAX] = {10, 100, 200};
int *ptr; // let us have address of the first element in pointer.
ptr =&var;
int i = 0;
while ( ptr <= &var[MAX - 1] )
{
cout << "Address of var[" << i << "] = ";
cout << ptr << endl;
cout << "Value of var[" << i << "] = ";
cout << *ptr << endl; // point to the previous location ptr++;
i++;
}
return 0;

More Related Content

PPTX
Pointer in c
PPTX
Function Pointer
PPTX
Pointers in c++
PPTX
Pointer to function 1
PPTX
This pointer
PPTX
Pointers in C/C++ Programming
PPT
Pointers (Pp Tminimizer)
PDF
10. array & pointer
Pointer in c
Function Pointer
Pointers in c++
Pointer to function 1
This pointer
Pointers in C/C++ Programming
Pointers (Pp Tminimizer)
10. array & pointer

What's hot (20)

PPTX
Pointers in c++
PPTX
c++ pointers by Amir Hamza Khan (SZABISTIAN)
PPT
pointers
PPTX
Pointers in c v5 12102017 1
PDF
C Pointers
PPTX
Pointer in C++
PDF
Pointer in c++ part2
PPTX
Pointers in c++
PDF
Pointers
PPTX
COM1407: Working with Pointers
PPTX
Pointer in C
PPT
Pointers C programming
PDF
Pointer in c++ part3
PDF
PPT
Object Range
PPTX
Pointer to function 2
PPT
Presentation
PPTX
C programming - Pointers
PPT
Unit 6 pointers
PPT
Pointers in c++
c++ pointers by Amir Hamza Khan (SZABISTIAN)
pointers
Pointers in c v5 12102017 1
C Pointers
Pointer in C++
Pointer in c++ part2
Pointers in c++
Pointers
COM1407: Working with Pointers
Pointer in C
Pointers C programming
Pointer in c++ part3
Object Range
Pointer to function 2
Presentation
C programming - Pointers
Unit 6 pointers
Ad

Similar to Array of pointer (20)

PPTX
L4_Pointer Arithmetic in C++.pptxhwhwjwjw
PPTX
pointers.pptx
PPTX
C++ Pointer | Introduction to programming
PPTX
POLITEKNIK MALAYSIA
PPT
FP 201 - Unit 6
PPTX
Object Oriented Programming using C++: Ch10 Pointers.pptx
PPTX
c++ arrays and pointers grade 9 STEP curriculum.pptx
PPTX
INTRODUCTION TO POINTER IN c++ AND POLYMORPHISM
PDF
C++ computer language chapter 4 pointers.pdf
PPTX
Pf cs102 programming-9 [pointers]
PPTX
POINTERS IN C - BTECH BCA CS AND IT PRESENTATIONS
PPTX
week14Pointers_II. pointers pemrograman dasar C++.pptx
PPT
Pointer
PDF
Pointers
PPTX
Chapter 3 summaryv2(Pointers) in c++.pptx
PPTX
Ponters
PDF
U3_4_PointerArithmetic.pdf people will use the above preaentationa dn
PPT
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
PPTX
Pointers and single &multi dimentionalarrays.pptx
L4_Pointer Arithmetic in C++.pptxhwhwjwjw
pointers.pptx
C++ Pointer | Introduction to programming
POLITEKNIK MALAYSIA
FP 201 - Unit 6
Object Oriented Programming using C++: Ch10 Pointers.pptx
c++ arrays and pointers grade 9 STEP curriculum.pptx
INTRODUCTION TO POINTER IN c++ AND POLYMORPHISM
C++ computer language chapter 4 pointers.pdf
Pf cs102 programming-9 [pointers]
POINTERS IN C - BTECH BCA CS AND IT PRESENTATIONS
week14Pointers_II. pointers pemrograman dasar C++.pptx
Pointer
Pointers
Chapter 3 summaryv2(Pointers) in c++.pptx
Ponters
U3_4_PointerArithmetic.pdf people will use the above preaentationa dn
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Pointers and single &multi dimentionalarrays.pptx
Ad

More from fasalsial1fasalsial1 (6)

PPTX
Experimental research
PPTX
PPTX
Operating system
PPTX
object oriented programming using c++
PPTX
Digital and logic design
PPTX
Experimental research
Operating system
object oriented programming using c++
Digital and logic design

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Machine learning based COVID-19 study performance prediction
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
cuic standard and advanced reporting.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
NewMind AI Weekly Chronicles - August'25 Week I
sap open course for s4hana steps from ECC to s4
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
cuic standard and advanced reporting.pdf
Network Security Unit 5.pdf for BCA BBA.
Reach Out and Touch Someone: Haptics and Empathic Computing
Advanced methodologies resolving dimensionality complications for autism neur...
Cloud computing and distributed systems.
Encapsulation_ Review paper, used for researhc scholars
Spectral efficient network and resource selection model in 5G networks
Mobile App Security Testing_ A Comprehensive Guide.pdf
Programs and apps: productivity, graphics, security and other tools
20250228 LYD VKU AI Blended-Learning.pptx
Building Integrated photovoltaic BIPV_UPV.pdf

Array of pointer

  • 1. ARRAY OF POINTER SUBMITTED BY: IRUM ABDULLAH SUBMITTED TO: MISS ZAINAB
  • 2. WHAT IS ARRAY OF POINTER? An array of pointer is an array in which eachelement is a pointer. Each element in the array can store a memory address. The array can store the memory addresses of different objects of data.
  • 3. FOR EXAMPLE #include<iostream.h> #include<conio.h> Void main() { clrscr() Int*ptr[3],a,b,c; Int i; Ptr[0]=&a; Ptr[1]=&b; Ptr[2]=&c; cout<<“enter three integer:”<<endl; cin>>a>>b>>c; cout<<“you enter the following values:n”; for(i=0;i<3;i++) cout<<*ptr[i]<<endl; getch(); }
  • 4. HOW ABOVE EXAMPLE WORK? The above program declares an array of integer pointer and three integer variables. Each element of pointer array refers to different variable. The program input values to the variables and display them using array of pointer.
  • 7. ARITHMETIC OPERATION ON POINTER  Indirection (*): This operator is used to get the value from the pointed address.  Reference operator( &): This operator is used get the address of the variable or pointer.  Assignment ( =): You can assign the value to the pointer or value to the address which is pointed by the pointer.  Incrementing: You can add integer value to the pointer to point the different memory location.  Decrementing: You can subtract the integer value from the pointer to point the different memory location.  Comparison :This operation is valid only between two pointers that point to the same array.
  • 8. DECREMENT A POINTER The same considerations apply to decrementing a pointer, which decreases its value by the number of bytes of its data type as shown below
  • 9. PROGRAM BY USING DECREMENT ON A POINTER #include <iostream> using namespace std; const int MAX = 3; int main () { int var[MAX] = {10, 100, 200}; int *ptr; // let us have address of the last element in pointer. ptr = &var[MAX-1]; for (int i = MAX; i > 0; i--) { cout << "Address of var[" << i << "] = "; cout << ptr << endl; cout << "Value of var[" << i << "] = "; cout << *ptr << endl; // point to the previous location ptr--; } return 0; }
  • 10. INCREMENT A POINTER We prefer using a pointer in our program instead of an array because the variable pointer can be incremented, unlike the array name which cannot be incremented because it is a constant pointer. The following program increments the variable pointer to access each succeeding element of the array −
  • 11. PROGRAME USING INCREMENT OPERATOR #include <iostream> using namespace std; const int MAX = 3; int main () { int var[MAX] = {10, 100, 200}; int *ptr; // let us have array address in pointer. ptr = var; for (int i = 0; i < MAX; i++) { cout << "Address of var[" << i << "] = "; cout << *ptr << endl; cout << "Value of var[" << i << "] = "; cout << *ptr << endl; // point to the next location ptr++; } return 0; }
  • 12. COMPARISON ON POINTER  Pointers may be compared by using relational operators, such as ==, <, and >. If p1 and p2 point to variables that are related to each other, such as elements of the same array, then p1 and p2 can be meaningfully compared.  The following program modifies the previous example one by incrementing the variable pointer so long as the address to which it points is either less than or equal to the address of the last element of the array, which is &var[MAX - 1] −
  • 13. PROGRAM BY USING COMPARISON ON A POINTER #include <iostream> using namespace std; const int MAX = 3; int main () { int var[MAX] = {10, 100, 200}; int *ptr; // let us have address of the first element in pointer. ptr =&var; int i = 0; while ( ptr <= &var[MAX - 1] ) { cout << "Address of var[" << i << "] = "; cout << ptr << endl; cout << "Value of var[" << i << "] = "; cout << *ptr << endl; // point to the previous location ptr++; i++; } return 0;