SlideShare a Scribd company logo
Complete the following code by deallocating the memory. Int *ptr1; int *ptr2; ptr1 = new Int;
ptr2 = new intl[10]; *ptr1 = 10;
Solution
Dear Student,
The memory in c++ is created by a operator call new.
And the memory is deallocated by a operator called delete.
Below is the complete program...
#include
using namespace std;
int main()
{
int *ptr1;
int *ptr2;
ptr1 = new int; //allocate memory for the variable
ptr2= new int[10]; // allocate memory for integer variable which size is 10.
*ptr1=10; // assignment of value to pointer
cout << *ptr1 << endl;
delete ptr1; //Deallocate memory allocated for ptr1
delete ptr2; //Deallocate memory allocated for ptr2
return 0;
}
Output : 10
Note- The above program is tested on g++ compiler under ubuntu 14.04 system.
***** Dear Student if you are satisfied with the answer kindly provide your valubale
feedback******

More Related Content

PPTX
Pointers in c++ programming presentation
PPTX
#OOP_D_ITS - 2nd - C++ Getting Started
PPTX
#OOP_D_ITS - 3rd - Pointer And References
PPTX
ADK COLEGE.pptx
PPT
Computer Programming- Lecture 7
PDF
The following code is an implementation of the producer consumer pro.pdf
PPTX
Pointers in c++ programming presentation
#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 3rd - Pointer And References
ADK COLEGE.pptx
Computer Programming- Lecture 7
The following code is an implementation of the producer consumer pro.pdf

Similar to Complete the following code by deallocating the memory. Int ptr1; .pdf (20)

PDF
Chapter16 pointer
PDF
C++_notes.pdf
PDF
Computer programming course(c++ pointer))
PDF
The following is the (incomplete) header file for the class Fracti.pdf
PPTX
TensorRT survey
PDF
C++11 & C++14
PPTX
Pointer to Member Function.pptx pointer in c++
PDF
write the To Dos to get the exact outputNOte A valid Fraction .pdf
PDF
Modify this code to use multiple threads with the same data1.Modif.pdf
PDF
Engineering Problem Solving With C++ 4th Edition Etter Solutions Manual
PPT
Object Oriented Technologies
PDF
Practiceproblems(1)
PDF
Structures and pointers-2_240731_192519.pdf
PPT
FP 201 - Unit 6
PPTX
Dynamic memory allocation in c++
PDF
A function definition num_digits with Cpp programnum_digits.cpp#.pdf
PPTX
clc02_cpp_presentation_edit3 (1) 1.pptx
PPT
Pointer
PPT
Link list
PPTX
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
Chapter16 pointer
C++_notes.pdf
Computer programming course(c++ pointer))
The following is the (incomplete) header file for the class Fracti.pdf
TensorRT survey
C++11 & C++14
Pointer to Member Function.pptx pointer in c++
write the To Dos to get the exact outputNOte A valid Fraction .pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
Engineering Problem Solving With C++ 4th Edition Etter Solutions Manual
Object Oriented Technologies
Practiceproblems(1)
Structures and pointers-2_240731_192519.pdf
FP 201 - Unit 6
Dynamic memory allocation in c++
A function definition num_digits with Cpp programnum_digits.cpp#.pdf
clc02_cpp_presentation_edit3 (1) 1.pptx
Pointer
Link list
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx

More from Dhanrajsolanki2091 (20)

PDF
Please I need help with this....Please also provide comments in each.pdf
PDF
Please give me the origin and history on Hassall’s corpusclesSol.pdf
PDF
OBJ. 2 PE 12-2A Dividing partnership net income Han Lee and Monica An.pdf
PDF
O’Connor says that Aristotelian justice “overcomes misorientation to.pdf
PDF
Let T R^5 rightarrow R^3 be a linear transformation whose null space.pdf
PDF
Make drawings of both organisms stained in each staining procedure. L.pdf
PDF
Link to TextThese selected condensed data are taken from a recent ba.pdf
PDF
Java Database Connect Write a program that views, inserts, and u.pdf
PDF
JUST DO QUESTION 32) You have discussed with the human resource ma.pdf
PDF
Ins struction Use the information that is associated with your name .pdf
PDF
I how does double fertilization aid in the survival of land plants o.pdf
PDF
how does malpractice affect quality of healthcare service What are .pdf
PDF
How can critical researchers claim to represent groups to which they.pdf
PDF
Discuss Allport’s concept of psychological healthy personality.Des.pdf
PDF
Earning revenue journal entry is recorded asA Increases assets.pdf
PDF
Discuss why is it important to use logical and physical data flow di.pdf
PDF
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
PDF
Define each of the following terms. Be clear whether it is at develop.pdf
PDF
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
PDF
Briefly discuss why you are proud to be a mammal and give examples of.pdf
Please I need help with this....Please also provide comments in each.pdf
Please give me the origin and history on Hassall’s corpusclesSol.pdf
OBJ. 2 PE 12-2A Dividing partnership net income Han Lee and Monica An.pdf
O’Connor says that Aristotelian justice “overcomes misorientation to.pdf
Let T R^5 rightarrow R^3 be a linear transformation whose null space.pdf
Make drawings of both organisms stained in each staining procedure. L.pdf
Link to TextThese selected condensed data are taken from a recent ba.pdf
Java Database Connect Write a program that views, inserts, and u.pdf
JUST DO QUESTION 32) You have discussed with the human resource ma.pdf
Ins struction Use the information that is associated with your name .pdf
I how does double fertilization aid in the survival of land plants o.pdf
how does malpractice affect quality of healthcare service What are .pdf
How can critical researchers claim to represent groups to which they.pdf
Discuss Allport’s concept of psychological healthy personality.Des.pdf
Earning revenue journal entry is recorded asA Increases assets.pdf
Discuss why is it important to use logical and physical data flow di.pdf
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
Define each of the following terms. Be clear whether it is at develop.pdf
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
Briefly discuss why you are proud to be a mammal and give examples of.pdf

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
master seminar digital applications in india
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Insiders guide to clinical Medicine.pdf
GDM (1) (1).pptx small presentation for students
Sports Quiz easy sports quiz sports quiz
Microbial disease of the cardiovascular and lymphatic systems
Supply Chain Operations Speaking Notes -ICLT Program
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Pharma ospi slides which help in ospi learning
STATICS OF THE RIGID BODIES Hibbelers.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Microbial diseases, their pathogenesis and prophylaxis
PPH.pptx obstetrics and gynecology in nursing
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Module 4: Burden of Disease Tutorial Slides S2 2025
master seminar digital applications in india
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape

Complete the following code by deallocating the memory. Int ptr1; .pdf

  • 1. Complete the following code by deallocating the memory. Int *ptr1; int *ptr2; ptr1 = new Int; ptr2 = new intl[10]; *ptr1 = 10; Solution Dear Student, The memory in c++ is created by a operator call new. And the memory is deallocated by a operator called delete. Below is the complete program... #include using namespace std; int main() { int *ptr1; int *ptr2; ptr1 = new int; //allocate memory for the variable ptr2= new int[10]; // allocate memory for integer variable which size is 10. *ptr1=10; // assignment of value to pointer cout << *ptr1 << endl; delete ptr1; //Deallocate memory allocated for ptr1 delete ptr2; //Deallocate memory allocated for ptr2 return 0; } Output : 10 Note- The above program is tested on g++ compiler under ubuntu 14.04 system. ***** Dear Student if you are satisfied with the answer kindly provide your valubale feedback******