SlideShare a Scribd company logo
1 of 11
Author – Subhasis Nayak
   It means a program can obtain required
    memory at runtime. Run time means when
    the program starts executing not compile
    time.
   In C++ for dynamic memory allocation we
    have two uninary operators.
    ◦ New
    ◦ Delete
   It is used to allocate the memory space when
    ever required.
   It is also used to create objects of all types,
    including a class name.
   You can allocate memory to a pointer only at
    runtime. Syntax is:
    ◦ Pointer-variable = new data-type
      the data type may be a valid C++ data type
      Pointer-variable is a pointer of type data-type
   The type of allocating memory must be same to
    the receiving pointer. it means, you can allocate
    only integer type memory to an integer type
    pointer.


    Int *p = new int;        Int *p = new char;

                 correct       incorrect
   To assign value to a pointer we have to pass a
    value using “( )” .
   Syntax will be:
    ◦ *p =100;


int *p =new int;
*p =200                 int *p =new int(200);
   When an object, is not in use we must free the
    memory captured by that object. So to free the
    captured memory is done by “delete” operator.
   The syntax is:
    ◦ Delete pointer-variable.

                        Int *p = new int;
                        ----;
                        ----;
                        delete *p;
   We can use the keyword const for pointers
    before the type, after the type, or in both
    places. For example, all the following
    declarations are legal:
    ◦ const int * p;
    ◦ int * const q;
    ◦ const int * const r;
   Each of the above having different meaning
    and different tasks.
   *p is a pointer to a constant integer. The
    value that is pointed to can‟t be changed.
   We can say the int pointed to a constant.
   „q‟ is a constant pointer to an integer. The
    integer can be changed, but „q‟ can‟t point to
    anything else.
   „q‟ is constant, it can‟t point to anything else.
   „r‟ is a constant pointer to a constant integer.
    The value that is pointed to can‟t be changed,
    and „r‟ can‟t be changed to point to anything
    else.

More Related Content

What's hot

Pointers in c
Pointers in cPointers in c
Pointers in c
Mohd Arif
 

What's hot (20)

Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Pointer in c++ part2
Pointer in c++ part2Pointer in c++ part2
Pointer in c++ part2
 
Used of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingUsed of Pointer in C++ Programming
Used of Pointer in C++ Programming
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
Pointers in C/C++ Programming
Pointers in C/C++ ProgrammingPointers in C/C++ Programming
Pointers in C/C++ Programming
 
Pointers
PointersPointers
Pointers
 
This pointer
This pointerThis pointer
This pointer
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2
 
C Pointers
C PointersC Pointers
C Pointers
 
pointers
pointerspointers
pointers
 
8 Pointers
8 Pointers8 Pointers
8 Pointers
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Pointer
PointerPointer
Pointer
 
C pointers
C pointersC pointers
C pointers
 
Module 02 Pointers in C
Module 02 Pointers in CModule 02 Pointers in C
Module 02 Pointers in C
 
Ponters
PontersPonters
Ponters
 

Viewers also liked (10)

Structures
StructuresStructures
Structures
 
Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
 
Arrays in C
Arrays in CArrays in C
Arrays in C
 
Amazon Web Services
Amazon Web ServicesAmazon Web Services
Amazon Web Services
 
jal hi jivan hai pre prentation
jal hi jivan hai pre prentationjal hi jivan hai pre prentation
jal hi jivan hai pre prentation
 
One dimensional arrays
One dimensional arraysOne dimensional arrays
One dimensional arrays
 
Array in C
Array in CArray in C
Array in C
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Arrays
ArraysArrays
Arrays
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 

Similar to Pointer in c++ part3

C++ Pointers with Examples.docx
C++ Pointers with Examples.docxC++ Pointers with Examples.docx
C++ Pointers with Examples.docx
JoeyDelaCruz22
 
2.Types_Variables_Functions.pdf
2.Types_Variables_Functions.pdf2.Types_Variables_Functions.pdf
2.Types_Variables_Functions.pdf
TrnThBnhDng
 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
chintuyadav19
 

Similar to Pointer in c++ part3 (20)

2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
 
COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
 
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
 
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
 
Pointers
PointersPointers
Pointers
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
C++ Pointers with Examples.docx
C++ Pointers with Examples.docxC++ Pointers with Examples.docx
C++ Pointers with Examples.docx
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
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
 
2.Types_Variables_Functions.pdf
2.Types_Variables_Functions.pdf2.Types_Variables_Functions.pdf
2.Types_Variables_Functions.pdf
 
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
 
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
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Pointers
PointersPointers
Pointers
 
Pointers
PointersPointers
Pointers
 
C Programming Unit-4
C Programming Unit-4C Programming Unit-4
C Programming Unit-4
 
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
 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
 

More from Subhasis Nayak

More from Subhasis Nayak (18)

Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)
 
working with database using mysql
working with database using mysql working with database using mysql
working with database using mysql
 
Php, mysq lpart3
Php, mysq lpart3Php, mysq lpart3
Php, mysq lpart3
 
Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)
 
Jsp 01
Jsp 01Jsp 01
Jsp 01
 
Jsp 02(jsp directives)2003
Jsp 02(jsp directives)2003Jsp 02(jsp directives)2003
Jsp 02(jsp directives)2003
 
Php, mysq lpart1
Php, mysq lpart1Php, mysq lpart1
Php, mysq lpart1
 
Php, mysqlpart2
Php, mysqlpart2Php, mysqlpart2
Php, mysqlpart2
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 
Servlet & jsp
Servlet  &  jspServlet  &  jsp
Servlet & jsp
 
J2ee connector architecture
J2ee connector architectureJ2ee connector architecture
J2ee connector architecture
 
how to create object
how to create objecthow to create object
how to create object
 
C++ arrays part2
C++ arrays part2C++ arrays part2
C++ arrays part2
 
C++ arrays part1
C++ arrays part1C++ arrays part1
C++ arrays part1
 
Introduction to network
Introduction to networkIntroduction to network
Introduction to network
 
Flow control in c++
Flow control in c++Flow control in c++
Flow control in c++
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ Fundamentals
 
Text mode Linux Installation Part 01
Text mode Linux Installation Part 01Text mode Linux Installation Part 01
Text mode Linux Installation Part 01
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

Pointer in c++ part3

  • 2. It means a program can obtain required memory at runtime. Run time means when the program starts executing not compile time.  In C++ for dynamic memory allocation we have two uninary operators. ◦ New ◦ Delete
  • 3. It is used to allocate the memory space when ever required.  It is also used to create objects of all types, including a class name.  You can allocate memory to a pointer only at runtime. Syntax is: ◦ Pointer-variable = new data-type  the data type may be a valid C++ data type  Pointer-variable is a pointer of type data-type
  • 4. The type of allocating memory must be same to the receiving pointer. it means, you can allocate only integer type memory to an integer type pointer. Int *p = new int; Int *p = new char; correct incorrect
  • 5. To assign value to a pointer we have to pass a value using “( )” .  Syntax will be: ◦ *p =100; int *p =new int; *p =200 int *p =new int(200);
  • 6.
  • 7. When an object, is not in use we must free the memory captured by that object. So to free the captured memory is done by “delete” operator.  The syntax is: ◦ Delete pointer-variable. Int *p = new int; ----; ----; delete *p;
  • 8. We can use the keyword const for pointers before the type, after the type, or in both places. For example, all the following declarations are legal: ◦ const int * p; ◦ int * const q; ◦ const int * const r;  Each of the above having different meaning and different tasks.
  • 9. *p is a pointer to a constant integer. The value that is pointed to can‟t be changed.  We can say the int pointed to a constant.
  • 10. „q‟ is a constant pointer to an integer. The integer can be changed, but „q‟ can‟t point to anything else.  „q‟ is constant, it can‟t point to anything else.
  • 11. „r‟ is a constant pointer to a constant integer. The value that is pointed to can‟t be changed, and „r‟ can‟t be changed to point to anything else.