answersLogoWhite

0


Best Answer

You can't physically delete memory, you can only delete a pointer to allocated memory, which subsequently releases the memory back to the system. The operator is delete, passing the pointer as the operand. If the pointer points to an array, then you must also use the index operator [] in front of the pointer name.

int main()

{

// pointer to an int type with value 100

int* ptr_int = new int(100);

// ... use pointer ...

// release the integer

delete ptr_int;

// pointer to an array 100 int types (with undefined values)

int* ptr_int_array = new int[100];

// ... use array ...

// release the array

delete [] ptr_int_array;

return(0);

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Delete memory release operator in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why use new and delete operator overloading in c plus plus?

one reason to use new and delete operator overloading in c++ is when you are using your own memory manager code. when the user of your code calls the new keywork, your memory manager code can allocate memory.


How does C Plus Plus handle dynamic memory allocation?

To allocate memory in C++ you use the new operator. To release the memory, you use the delete operator.double *myArray = new float [1000];//check and usedelete [] myArray;myClass *myClassInstance = new myClass;//check and usedelete myClassInstance;


What is the operator is used to allocate the memory in c plus plus?

calloc operator,malloc operator


How do you find size of any object in java OR is there any operator or fun.. equivalent size of in c plus plus?

No, there is no such operator or function in Java that can tell you the amount of memory an object uses.


Program for new and delete operator using c plus plus?

#include<iostream> struct object { int m_data; }; void main() { object obj=new object; obj.m_data = 42; delete( obj ); return( 0 ); }

Related questions

What is the memory management operator in c plus plus?

There is no memory management operator in C++ -- it is an unmanaged language. You use the C++ new operator to allocate memory, and use the C++ delete operator to release previously allocated memory.


Which operator is used for deallocating memory in c plus plus?

delete


Why use new and delete operator overloading in c plus plus?

one reason to use new and delete operator overloading in c++ is when you are using your own memory manager code. when the user of your code calls the new keywork, your memory manager code can allocate memory.


What are new and delete operators in c plus plus?

New and Delete are the memory management operators in c++,like c language we use malloc() and calloc() functions to allocate memory and free() functiong to release the memory similarily we use new to allocate memory in C++ and Delete to release the allocated memory....


How does C Plus Plus handle dynamic memory allocation?

To allocate memory in C++ you use the new operator. To release the memory, you use the delete operator.double *myArray = new float [1000];//check and usedelete [] myArray;myClass *myClassInstance = new myClass;//check and usedelete myClassInstance;


What is the operator is used to allocate the memory in c plus plus?

calloc operator,malloc operator


Do you have to use delete operator on C plus plus strings before exiting your application?

no you dont


When you call new will it internally call delete in c plus plus?

No. Calling new returns a pointer to allocated memory. If you re-use a pointer to store the return value, then you must release the memory that it previously pointed at, either by deleting the pointer, or by maintaining a separate pointer to the original memory. Calling new will not release the current memory for you.


How do you find size of any object in java OR is there any operator or fun.. equivalent size of in c plus plus?

No, there is no such operator or function in Java that can tell you the amount of memory an object uses.


Are new and delete operators in c plus plus related to flush?

The new and delete operators in C++ are not related to flush. New is used to allocate memory, while delete is used to deallocate memory. Flush is a library concept that allows you to ensure that IO is completed, and not buffered, before proceeding to the next step.


Program for new and delete operator using c plus plus?

#include<iostream> struct object { int m_data; }; void main() { object obj=new object; obj.m_data = 42; delete( obj ); return( 0 ); }


Write c plus plus program for new and delete operator using class?

#include<iostream> class foo{ int m_data; }; int main() { foo* p=new foo; delete( foo), foo=NULL; return(0); }