1.

Solve : new and delete?

Answer»

What does the NEw and delete operators do in c++...
i looked thru several sites..but it made me more confused..
so can any one tell me what these two keywords do..PLZ explain in detail..
and also can anyone tell me what the
using namespace std; does and means....my advise, you should get a C++ book instead.An object created with operator new() or operator new[]() exists until the operator delete() or operator delete[]() is called to deallocate the object's MEMORY. A delete operator or a destructor will not be implicitly called for an object created with a new that has not been explicitly deallocated before the end of the program.
Using namespace std is used when you want to ACCESS objects, functions, classes, variables and all that declared inside the std namespace.
To be more specific, it allows you to refer to functions, classes, and anything else publicly available in the std namespace without the use of a qualified name.

For example

using namespace std;
cout << "Hello World\n";

as opposed to
std::cout << "Hello World\n";

The first uses an unqualifed name, the second uses a qualified name.can u GIVE an example of how to use new and delete operators with examplesi FIGURED i should find a link instead.
try this site.This is usually, in my programs, used to put new object instances on the free store rather than the stack, therefore making it easy to create objects inside separate functions.

//Stuff...
Cat *newCat = createCat(5, male, 10);
// . . .

Cat * createCat(int age, gender sex, int weight)
{
Cat newCat = new Cat(age, sex, weight);
return *newCat;
}

In the above gross oversimplification, the new function isn't necessary. But if I needed a tree of if...else if...else statements, a case block, or any other thing that would take up a lot of code space, I could do that. Whenever I don't need the new cat, I call the delete() function on it.



Discussion

No Comment Found