SlideShare a Scribd company logo
P. Nivetha,
Dept. of BCA,
Bon Secours college for Women,
Thanjavur.
What is Pointer?
1.Pointer is a variable that holds a memory
address, usually location of another variable.
2.The Pointers are one of the C++’s most useful
and powerful features.
How Pointers are one of the C++’s
most useful and powerful features?
1.Pointer provide the means through which the memory
location of variable can be directly accessed and
hence it can be manipulated in the way as required.
2.Pointer supports C++ dynamic allocation routines.
3.Pointer can improve the efficiency of certain routines..
DYNAMIC AND STATIC
MEMORY ALLOCATION
The Golden Rule of computer states that
anything or everything that needs to be
processed must be loaded into internal
memory before its processing takes place.
Therefore the main memory is allocated in two
ways,
STATIC MEMORY ALLOCATION
DYNAMIC MEMORY ALLOCATION
STATIC MEMORY
ALLOCATION
In this technique the demanded memory is
allocated in advance that is at the compilation
time is called static memory allocation.
For example,
int s;
The compiler allocates the 2 bytes of memory
before its execution.
DYNAMIC MEMORY
ALLOCATION
In this technique the memory is allocated as
and when required during run time (program
execution) is called Dynamic memory
allocation.
C++ offers two types of operators called new
and delete to allocate and de-allocate the
memory at runtime.
FREE STORE
FREE STORE is a pool of unallocated heap
memory given to a program that is used by the
program for dynamic allocation during
execution.
DECLARATION AND
INITIALIZATION OF POINTERS
Pointer variables are declared like normal
variables except for the addition of unary
operator * (character)
The General Format of Pointer variable
declaration is ,
type * var_name;
where ,
type refers to any C++ valid data type and
var_name is any valid C++ variable
DECLARATION AND
INITIALIZATION OF POINTERS
For example,
int *iptr; // integer pointer variable points
to //another integer variable’s location.
float *fptr; // float type pointer variable points
to //another float type variable’s location.
char *cptr; // character type pointer variable
//points to another char type variable’s location.
POINTER AIRTHMETIC
Only two arithmetic operators, addition and
subtraction may be performed on pointers.
When you add 1 to a pointer, you are actually
adding the size of what ever the pointer
pointing at.
For example,
iptr++;
iptr--;
POINTER AIRTHMETIC
Only two arithmetic operators, addition and
subtraction may be performed on pointers.
When you add 1 to a pointer, you are actually
adding the size of what ever the pointer pointing
at.
For example,
iptr++;
iptr--;
Note: In pointer arithmetic all pointers increase
and decrease by the length of the data type they
point to.
DYNAMIC ALLOCATION OPERATORS -
new OPERATOR
C++ offers two types of operators called new and
delete to allocate and de-allocate the memory at
runtime. Since these two operators operate upon free
store memory, they are also called as free store
operators
Syntax :
pointer_variable = new data type;
where pointer_variable pointer variable and datatype
is valid C++ datatype and new is operator which
allocates the memory (size of data type) at run time.
For example,
int *iptr=new int;
char *cptr=new char;
float *fptr=new float;
Once a pointer points to newly allocated memory,
data values can be stored there using at address
operator
*cptr=‘a’;
*fptr=1.34;
*iptr=89;
DYNAMIC ALLOCATION OPERATORS -
new OPERATOR
Initializing values at the time of declaration one can
rewrite like,
int *iptr=new int(89);
char *cptr=new char(‘a’);
float *fptr=new float(1.34);
DYNAMIC ALLOCATION OPERATORS -
new OPERATOR
DYNAMIC ALLOCATION OPERATORS
CREATING DYNMIC ARRAYS 1D ARRAYS:
Syntax :
pointer_variable = new data type[size];
int *value=new int[10];
It will create memory space from the free store to
store 10 integers. Initilization while declaring dynamic
array is not possible but it is included in C++ compiler
ver 11.
CREATING DYNMIC ARRAYS (2D ARRAYS):
One needs to be tricky while defining 2D array as,
int *val,r,c,i,j;
cout<<“Enter dimensions”;
cin>>r>>c;
val=new int [ r * c ] ;
To read the elements of the 2D array
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
cin>> val [ i *c + j ] ;
}
DYNAMIC ALLOCATION OPERATORS -
new OPERATOR
The life time of the variable or object created by new is not
restricted to the scope in which it is created. It lives in the
memory until explicitly deleted using the delete operator.
Syntax:
delete pointer_variable;
For example, delete iptr;
FOR ARRAYS :
Syntax :
delete [ ] arraypointer_variable;
delete [ ] val;
DYNAMIC ALLOCATION OPERATORS -
delete OPERATOR

More Related Content

PPS
Aae oop xp_06
PDF
Chapter16 pointer
PPT
Pointers (Pp Tminimizer)
PPT
PPTX
Pointers in c++
PPT
Pointer
PDF
Pointer in c++ part3
PPTX
Pointers in c++
Aae oop xp_06
Chapter16 pointer
Pointers (Pp Tminimizer)
Pointers in c++
Pointer
Pointer in c++ part3
Pointers in c++

What's hot (20)

PPTX
Pointer in c program
PPT
Introduction to pointers and memory management in C
PPTX
Presentation on pointer.
PPTX
Pointers in c++
PPTX
Unit 8. Pointers
PDF
Pointers & References in C++
PPT
Pointers in c
PDF
Lecturer23 pointersin c.ppt
PPTX
Pointers
PPTX
Dynamic Memory Allocation in C
PPTX
PPT
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
ODP
Pointers in c++ by minal
PPTX
Pointers in C
PDF
Module 02 Pointers in C
PPTX
Pointers in C/C++ Programming
PPTX
Used of Pointer in C++ Programming
PDF
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
PPT
C pointers
PPTX
Pointers in C Language
Pointer in c program
Introduction to pointers and memory management in C
Presentation on pointer.
Pointers in c++
Unit 8. Pointers
Pointers & References in C++
Pointers in c
Lecturer23 pointersin c.ppt
Pointers
Dynamic Memory Allocation in C
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Pointers in c++ by minal
Pointers in C
Module 02 Pointers in C
Pointers in C/C++ Programming
Used of Pointer in C++ Programming
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
C pointers
Pointers in C Language
Ad

Similar to Pointers (20)

PPTX
COM1407: Working with Pointers
PPTX
FYBSC(CS)_UNIT-1_Pointers in C.pptx
PPT
Lecture2.ppt
PPTX
2-Concept of Pointers in c programming.pptx
PPTX
Pointer.pptx
PDF
C programming session8
PDF
C programming session8
PPT
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
PDF
PSPC--UNIT-5.pdf
PPTX
pointers in c programming - example programs
PPT
358 33 powerpoint-slides_3-pointers_chapter-3
PPTX
pointer, virtual function and polymorphism
PPTX
Pointers, virtual function and polymorphism
PDF
0-Slot11-12-Pointers.pdf
PPTX
Pointer in C++
PPTX
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
PPT
PPT
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
PPT
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
COM1407: Working with Pointers
FYBSC(CS)_UNIT-1_Pointers in C.pptx
Lecture2.ppt
2-Concept of Pointers in c programming.pptx
Pointer.pptx
C programming session8
C programming session8
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
PSPC--UNIT-5.pdf
pointers in c programming - example programs
358 33 powerpoint-slides_3-pointers_chapter-3
pointer, virtual function and polymorphism
Pointers, virtual function and polymorphism
0-Slot11-12-Pointers.pdf
Pointer in C++
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Ad

Recently uploaded (20)

PPTX
History, Philosophy and sociology of education (1).pptx
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PPTX
Cell Types and Its function , kingdom of life
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
1_English_Language_Set_2.pdf probationary
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Computing-Curriculum for Schools in Ghana
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
History, Philosophy and sociology of education (1).pptx
LDMMIA Reiki Yoga Finals Review Spring Summer
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Cell Types and Its function , kingdom of life
Unit 4 Skeletal System.ppt.pptxopresentatiom
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
A powerpoint presentation on the Revised K-10 Science Shaping Paper
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Chinmaya Tiranga quiz Grand Finale.pdf
Complications of Minimal Access Surgery at WLH
UNIT III MENTAL HEALTH NURSING ASSESSMENT
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Indian roads congress 037 - 2012 Flexible pavement
1_English_Language_Set_2.pdf probationary
What if we spent less time fighting change, and more time building what’s rig...
Computing-Curriculum for Schools in Ghana
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
A systematic review of self-coping strategies used by university students to ...

Pointers

  • 1. P. Nivetha, Dept. of BCA, Bon Secours college for Women, Thanjavur.
  • 2. What is Pointer? 1.Pointer is a variable that holds a memory address, usually location of another variable. 2.The Pointers are one of the C++’s most useful and powerful features.
  • 3. How Pointers are one of the C++’s most useful and powerful features? 1.Pointer provide the means through which the memory location of variable can be directly accessed and hence it can be manipulated in the way as required. 2.Pointer supports C++ dynamic allocation routines. 3.Pointer can improve the efficiency of certain routines..
  • 4. DYNAMIC AND STATIC MEMORY ALLOCATION The Golden Rule of computer states that anything or everything that needs to be processed must be loaded into internal memory before its processing takes place. Therefore the main memory is allocated in two ways, STATIC MEMORY ALLOCATION DYNAMIC MEMORY ALLOCATION
  • 5. STATIC MEMORY ALLOCATION In this technique the demanded memory is allocated in advance that is at the compilation time is called static memory allocation. For example, int s; The compiler allocates the 2 bytes of memory before its execution.
  • 6. DYNAMIC MEMORY ALLOCATION In this technique the memory is allocated as and when required during run time (program execution) is called Dynamic memory allocation. C++ offers two types of operators called new and delete to allocate and de-allocate the memory at runtime.
  • 7. FREE STORE FREE STORE is a pool of unallocated heap memory given to a program that is used by the program for dynamic allocation during execution.
  • 8. DECLARATION AND INITIALIZATION OF POINTERS Pointer variables are declared like normal variables except for the addition of unary operator * (character) The General Format of Pointer variable declaration is , type * var_name; where , type refers to any C++ valid data type and var_name is any valid C++ variable
  • 9. DECLARATION AND INITIALIZATION OF POINTERS For example, int *iptr; // integer pointer variable points to //another integer variable’s location. float *fptr; // float type pointer variable points to //another float type variable’s location. char *cptr; // character type pointer variable //points to another char type variable’s location.
  • 10. POINTER AIRTHMETIC Only two arithmetic operators, addition and subtraction may be performed on pointers. When you add 1 to a pointer, you are actually adding the size of what ever the pointer pointing at. For example, iptr++; iptr--;
  • 11. POINTER AIRTHMETIC Only two arithmetic operators, addition and subtraction may be performed on pointers. When you add 1 to a pointer, you are actually adding the size of what ever the pointer pointing at. For example, iptr++; iptr--; Note: In pointer arithmetic all pointers increase and decrease by the length of the data type they point to.
  • 12. DYNAMIC ALLOCATION OPERATORS - new OPERATOR C++ offers two types of operators called new and delete to allocate and de-allocate the memory at runtime. Since these two operators operate upon free store memory, they are also called as free store operators Syntax : pointer_variable = new data type; where pointer_variable pointer variable and datatype is valid C++ datatype and new is operator which allocates the memory (size of data type) at run time.
  • 13. For example, int *iptr=new int; char *cptr=new char; float *fptr=new float; Once a pointer points to newly allocated memory, data values can be stored there using at address operator *cptr=‘a’; *fptr=1.34; *iptr=89; DYNAMIC ALLOCATION OPERATORS - new OPERATOR
  • 14. Initializing values at the time of declaration one can rewrite like, int *iptr=new int(89); char *cptr=new char(‘a’); float *fptr=new float(1.34); DYNAMIC ALLOCATION OPERATORS - new OPERATOR
  • 15. DYNAMIC ALLOCATION OPERATORS CREATING DYNMIC ARRAYS 1D ARRAYS: Syntax : pointer_variable = new data type[size]; int *value=new int[10]; It will create memory space from the free store to store 10 integers. Initilization while declaring dynamic array is not possible but it is included in C++ compiler ver 11.
  • 16. CREATING DYNMIC ARRAYS (2D ARRAYS): One needs to be tricky while defining 2D array as, int *val,r,c,i,j; cout<<“Enter dimensions”; cin>>r>>c; val=new int [ r * c ] ; To read the elements of the 2D array for(i=0;i<r;i++) { for(j=0;j<c;j++) cin>> val [ i *c + j ] ; } DYNAMIC ALLOCATION OPERATORS - new OPERATOR
  • 17. The life time of the variable or object created by new is not restricted to the scope in which it is created. It lives in the memory until explicitly deleted using the delete operator. Syntax: delete pointer_variable; For example, delete iptr; FOR ARRAYS : Syntax : delete [ ] arraypointer_variable; delete [ ] val; DYNAMIC ALLOCATION OPERATORS - delete OPERATOR