SlideShare a Scribd company logo
1 of 17
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

What's hot

Pointer in c program
Pointer in c programPointer in c program
Pointer in c programRumman Ansari
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in CUri Dekel
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++Ilio Catallo
 
Pointers in c
Pointers in cPointers in c
Pointers in cMohd Arif
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppteShikshak
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Jayanshu Gundaniya
 
Module 02 Pointers in C
Module 02 Pointers in CModule 02 Pointers in C
Module 02 Pointers in CTushar B Kute
 
Used of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingUsed of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingAbdullah Jan
 
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMYComputer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMYklirantga
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Languagemadan reddy
 

What's hot (20)

Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in C
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
 
Pointers
PointersPointers
Pointers
 
Dynamic Memory Allocation in C
Dynamic Memory Allocation in CDynamic Memory Allocation in C
Dynamic Memory Allocation in C
 
C pointer
C pointerC pointer
C pointer
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Module 02 Pointers in C
Module 02 Pointers in CModule 02 Pointers in C
Module 02 Pointers in C
 
Pointers in C/C++ Programming
Pointers in C/C++ ProgrammingPointers in C/C++ Programming
Pointers in C/C++ Programming
 
Used of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingUsed of Pointer in C++ Programming
Used of Pointer in C++ Programming
 
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMYComputer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
 
C pointers
C pointersC pointers
C pointers
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 

Similar to Pointers

FYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxFYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxsangeeta borde
 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptchintuyadav19
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3sumitbardhan
 
pointer, virtual function and polymorphism
pointer, virtual function and polymorphismpointer, virtual function and polymorphism
pointer, virtual function and polymorphismramya marichamy
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphismlalithambiga kamaraj
 
0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdf0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdfssusere19c741
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingMeghaj Mallick
 
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handlingBsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handlingRai University
 
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingMca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 

Similar to Pointers (20)

COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
 
FYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxFYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptx
 
Pointers
PointersPointers
Pointers
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3
 
pointer, virtual function and polymorphism
pointer, virtual function and polymorphismpointer, virtual function and polymorphism
pointer, virtual function and polymorphism
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
 
0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdf0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdf
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
 
Session 5
Session 5Session 5
Session 5
 
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handlingBsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
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
Diploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
 
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingMca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
 

Recently uploaded

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Recently uploaded (20)

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

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