Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Thread Tools Search this Thread
Old 08-12-2008
Join Date: Aug 2008
Posts: 157
Using new and delete Operators in C++

C++ offers programmers a means to create variables dynamically using new operator. The new operator determines the type of receiving pointer and converts its return value appropriately. Memory is allocated. To release the memory allocated,C++ uses delete operator.

The new operator, when used with the pointer to a data type, allocates memory for the item and assigns the address of that memory to the pointer. The delete operator does the reverse, it de-allocates the memory allocated to the variable. The C++ new operator is used to allocate memory from the heap. The advantage of the new operator is that it offers safety in terms of type and size. Whereas malloc only takes one argument, the desired size in bytes. The argument to the new operator identifies the type of the variable to create, which ensures that the user is getting memory of the intended size and type. When no longer needed, memory that is allocated with new should be deallocated with delete.

#include <iostream>
int main()
       char *name;                               //Declare a pointer
       name = new char[31];                  //Allocates 31 bytes memory for the object 
       cout<< "Enter name : " << endl;   //Will be displayed on the screen
       cin >> name;
       cout << name <<;
       delete [] name;                           //Destroys the object by de-allocating the memory
       return 0;
Reply With Quote
Old 10-12-2008
Join Date: May 2008
Posts: 2,008
Re: Using new and delete Operators in C++

C++ supports dynamic allocation and deallocation of objects using the new and delete operators. These operators allocate memory for objects from a pool called the free store. The new operator calls the special function operator new, and the delete operator calls the special function operator delete.
Reply With Quote

  TechArena Community > Software > Software Development
Tags: ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "Using new and delete Operators in C++"
Thread Thread Starter Forum Replies Last Post
How to use an Operators in PHP? Mr.ken Software Development 5 05-03-2010 06:23 AM
php operators and keywords Fragman Software Development 5 26-02-2010 06:15 PM
What are the Operators and Expressions in C# ? kyosang Software Development 4 09-02-2010 06:32 AM
overloading of operators in C++ shilong Software Development 3 28-01-2009 10:30 PM
Want info on C# Operators ashwinK Software Development 2 03-11-2008 02:31 PM

All times are GMT +5.5. The time now is 03:35 PM.