SlideShare a Scribd company logo
1 of 10
MEMORY MANAGEMENT IN C++
Presented by:- Chetan Raut.
Presented To:- Ms. Shalinee Pareek.
What’s in it for you ?
What is memory management ?
Why we need memory management ?
Memory allocation and deallocation in c++
C++ new operator
C++ delete operator
What is memory management ?
Memory management can be defined as the process to
manage a computer’s memory.
Example: Assigning memory to programs. Variables etc.
So, that it doesn’t affect the overall
performance.
Why we need memory management?
Memory management is required to avoid wastages of
memory and to make sure allocation takes place
efficiently.
During the declaration of arrays, sometimes the exact
memory is not known to us, and that is why we declare an
array of max size. Which results in memory wastages.
To avoid such case, we use memory allocation.
Memory allocation and deallocation in C++
Programming languages like java, python, etc. have the
compiler that manages the memory allocation.
In the case of C++, the allocation and deallocation of
memory are done manually.
In C++, there are two operators that is used for the
allocation and deallocation of memory.
1) New operator.
2) Delete operator.
C++ New Operator
The new operator in C++ is used for dynamic memory
allocation.
The new operator is responsible for the creation of the object.
Syntax:-
Pointer variable= new datatype;
Syntax for arrays:-
Pointer Variable = new datatype[size];
In case of arrays, the new keyword returns
the address of first element
Example
int *ptr;
ptr = new int;
*ptr= 75;
Keyword Data Type of pointer
C++ Delete Operator
The Delete operator in C++ is used for deallocation of memory or
for releasing of memory space.
Once the memory is no longer required, then we have to
deallocation the memory using the delete operator.
Syntax:-
delete Pointer variable;
Syntax for arrays:-
delete[]Pointer Variable;
Example
int *ptr;
ptr = new int;
*ptr= 75;
//After printing
delete ptr;
#include<iostream>
Using namespace std;
Int main(){
int *ptr1;
int *ptr2;
int *ptr3;
int avg;
ptr1= new int;
ptr2= new int;
ptr3=new int;
cout<<“Enter the first number: ”;
cin>>*ptr1;
cout<<“Enter the second number: ”;
cin>>*ptr2;
cout<<“Enter the third number: ”;
cin>>*ptr3;
}
avg=(*ptr1+*ptr2+*ptr3)/3;
cout<<“Average is : ”<<avg<<endl;
delete ptr1;
delete ptr2;
delete ptr3;
}
Output:-
Enter the first number: 5
Enter the second number: 5
Enter the third number: 2
Average is : 4
#include<iostream>
Using namespace std;
Int main(){
int size;
cout<<“Enter the size: ”;
cin>>size;
int *ptr;
ptr= new int[size];
cout<<“Enter the element: ”<<endl;
for(int i=0;i<size;i++)
{
cout<<“Element: ”;
cin>>ptr[i];
}
{ cout<<“nElements that you have entered : ”<<endl;
for(int i=0;i<size;i++)
{
cout<<“Element : ”<<ptr[i]<<endl;
}
delete ptr;
}
Output:-
Enter the size: 4
Enter the element:
Element: 2
Element: 4
Element: 7
Element: 9
Elements that you have entered :
Element: 2
Element: 4
Element: 7
Element: 9
THANK YOU

More Related Content

Similar to C++ MEMORY MANAGEMENT.pptx/ kbibuvvw veovn nveknev ovne onv

CS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2ndCS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2nd
Edward Chen
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
Qundeel
 
Data Structure
Data StructureData Structure
Data Structure
sheraz1
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
Qundeel
 

Similar to C++ MEMORY MANAGEMENT.pptx/ kbibuvvw veovn nveknev ovne onv (20)

C++.pptx
C++.pptxC++.pptx
C++.pptx
 
CS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2ndCS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2nd
 
Introduction to Data Structure and algorithm.pptx
Introduction to Data Structure and algorithm.pptxIntroduction to Data Structure and algorithm.pptx
Introduction to Data Structure and algorithm.pptx
 
memory
memorymemory
memory
 
8 Pointers
8 Pointers8 Pointers
8 Pointers
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
 
Data Structure
Data StructureData Structure
Data Structure
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
 
Safe Clearing of Private Data
Safe Clearing of Private DataSafe Clearing of Private Data
Safe Clearing of Private Data
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
Data Structures and Algorithms in Python
Data Structures and Algorithms in PythonData Structures and Algorithms in Python
Data Structures and Algorithms in Python
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 
Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02
 
Lecture 3.mte 407
Lecture 3.mte 407Lecture 3.mte 407
Lecture 3.mte 407
 
C++
C++C++
C++
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
PF UE LEC 7 Pointers programming fundamentals (2).pptx
PF UE LEC 7 Pointers programming fundamentals (2).pptxPF UE LEC 7 Pointers programming fundamentals (2).pptx
PF UE LEC 7 Pointers programming fundamentals (2).pptx
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notes
 

More from ChetanRaut43 (10)

Python 8416516 16 196 46 5163 51 63 51 6.pptx
Python 8416516 16 196 46 5163 51 63 51 6.pptxPython 8416516 16 196 46 5163 51 63 51 6.pptx
Python 8416516 16 196 46 5163 51 63 51 6.pptx
 
operatingsystem03handlingofinterrupts-210603182850.pdf
operatingsystem03handlingofinterrupts-210603182850.pdfoperatingsystem03handlingofinterrupts-210603182850.pdf
operatingsystem03handlingofinterrupts-210603182850.pdf
 
OS in 6 hours 640764073707670476407640.pdf
OS in 6 hours 640764073707670476407640.pdfOS in 6 hours 640764073707670476407640.pdf
OS in 6 hours 640764073707670476407640.pdf
 
AI 838686868686892868255383432434356.pptx
AI 838686868686892868255383432434356.pptxAI 838686868686892868255383432434356.pptx
AI 838686868686892868255383432434356.pptx
 
operatingsystem03handlingofinterrupts-210603182850.pptx
operatingsystem03handlingofinterrupts-210603182850.pptxoperatingsystem03handlingofinterrupts-210603182850.pptx
operatingsystem03handlingofinterrupts-210603182850.pptx
 
python 165813219816514981616098813219 (1).pptx
python 165813219816514981616098813219 (1).pptxpython 165813219816514981616098813219 (1).pptx
python 165813219816514981616098813219 (1).pptx
 
IOT 5541434546461631513232138248438.pptx
IOT 5541434546461631513232138248438.pptxIOT 5541434546461631513232138248438.pptx
IOT 5541434546461631513232138248438.pptx
 
Virtual Memory 53565686598386865286860.pdf
Virtual Memory 53565686598386865286860.pdfVirtual Memory 53565686598386865286860.pdf
Virtual Memory 53565686598386865286860.pdf
 
xmlnamespace-2201311329156484688 (1).pdf
xmlnamespace-2201311329156484688 (1).pdfxmlnamespace-2201311329156484688 (1).pdf
xmlnamespace-2201311329156484688 (1).pdf
 
Sack TCP Lecture13 all in one easily explain.ppt
Sack TCP Lecture13 all in one easily explain.pptSack TCP Lecture13 all in one easily explain.ppt
Sack TCP Lecture13 all in one easily explain.ppt
 

Recently uploaded

Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
amitlee9823
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
amitlee9823
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
karishmasinghjnh
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
amitlee9823
 

Recently uploaded (20)

Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning Approach
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
 

C++ MEMORY MANAGEMENT.pptx/ kbibuvvw veovn nveknev ovne onv

  • 1. MEMORY MANAGEMENT IN C++ Presented by:- Chetan Raut. Presented To:- Ms. Shalinee Pareek.
  • 2. What’s in it for you ? What is memory management ? Why we need memory management ? Memory allocation and deallocation in c++ C++ new operator C++ delete operator
  • 3. What is memory management ? Memory management can be defined as the process to manage a computer’s memory. Example: Assigning memory to programs. Variables etc. So, that it doesn’t affect the overall performance.
  • 4. Why we need memory management? Memory management is required to avoid wastages of memory and to make sure allocation takes place efficiently. During the declaration of arrays, sometimes the exact memory is not known to us, and that is why we declare an array of max size. Which results in memory wastages. To avoid such case, we use memory allocation.
  • 5. Memory allocation and deallocation in C++ Programming languages like java, python, etc. have the compiler that manages the memory allocation. In the case of C++, the allocation and deallocation of memory are done manually. In C++, there are two operators that is used for the allocation and deallocation of memory. 1) New operator. 2) Delete operator.
  • 6. C++ New Operator The new operator in C++ is used for dynamic memory allocation. The new operator is responsible for the creation of the object. Syntax:- Pointer variable= new datatype; Syntax for arrays:- Pointer Variable = new datatype[size]; In case of arrays, the new keyword returns the address of first element Example int *ptr; ptr = new int; *ptr= 75; Keyword Data Type of pointer
  • 7. C++ Delete Operator The Delete operator in C++ is used for deallocation of memory or for releasing of memory space. Once the memory is no longer required, then we have to deallocation the memory using the delete operator. Syntax:- delete Pointer variable; Syntax for arrays:- delete[]Pointer Variable; Example int *ptr; ptr = new int; *ptr= 75; //After printing delete ptr;
  • 8. #include<iostream> Using namespace std; Int main(){ int *ptr1; int *ptr2; int *ptr3; int avg; ptr1= new int; ptr2= new int; ptr3=new int; cout<<“Enter the first number: ”; cin>>*ptr1; cout<<“Enter the second number: ”; cin>>*ptr2; cout<<“Enter the third number: ”; cin>>*ptr3; } avg=(*ptr1+*ptr2+*ptr3)/3; cout<<“Average is : ”<<avg<<endl; delete ptr1; delete ptr2; delete ptr3; } Output:- Enter the first number: 5 Enter the second number: 5 Enter the third number: 2 Average is : 4
  • 9. #include<iostream> Using namespace std; Int main(){ int size; cout<<“Enter the size: ”; cin>>size; int *ptr; ptr= new int[size]; cout<<“Enter the element: ”<<endl; for(int i=0;i<size;i++) { cout<<“Element: ”; cin>>ptr[i]; } { cout<<“nElements that you have entered : ”<<endl; for(int i=0;i<size;i++) { cout<<“Element : ”<<ptr[i]<<endl; } delete ptr; } Output:- Enter the size: 4 Enter the element: Element: 2 Element: 4 Element: 7 Element: 9 Elements that you have entered : Element: 2 Element: 4 Element: 7 Element: 9