--%>

New Operator and Delete Operator

New operator: It allows dynamic storage allocation. It throws an exception if memory allocation fails. The general format of new operator is return type, pointer to data type.

The C++ statement

Allocates memory to variable ptrvar dynamically of specified data type and specified size. The operator new allocates a specified amount of memory during run time and returns a pointer to that memory allocation. It compares the size of memory allocated by

Size of (data type) * integer type size;

Where data type can be a standard data type or a user defined data type, integer size can be an integer expression, which specifies the number of element in the array. The new operators returns the NULL, if memory allocation is unsuccessful

Example:   Int * a = new (100);

It creates a memory for an integer and initializes it with 100.

Delete operator: This is used to return the memory allocated by new operator back to the memory pull. Memory thus released will be reused for other part of programme. Although memory allocated by is returned automatically to the system. When the programme terminates it is safer to use this operator explicitly within the pointer. This is absolutely necessary in situations where local variable pointing to the memory get destroyed when the function terminates leaving memory inaccessible to the rest of the delete operator is-

Deal locates the memory allocates to ptrvar. By de allocating the memory, the pointer variable does not get deleted and the address value stored in it does not change. However this address become invalid, as the returned memory will be used up for storing entirely different data. 

   Related Questions in Programming Languages

  • Q : Questions on java class Array 1.

    1. Suppose we have a class A which has a constructor that takes a single integer. (a) After the following statements have been executed, how many A objects will exist

  • Q : C-C++ interfaces into WLS JMS Normal 0

    Normal 0 false false

  • Q : Distinct features of Object oriented

    Q. What are the distinct features of Object oriented programming language?  

    Q : What is Boundary error Boundary error :

    Boundary error: The errors which arise from programming mistakes prepared at the edges of a problem- indexing off the edge of an array, commencing with no items of data, loop termination and so forth. Boundary errors are a very general type of logical

  • Q : Define Heap Abstractions Heap

    Heap Abstractions: The class abstractions that we discussed above are obtained by abstracting each field of base type. The number of instances of that particular class still needs to be bounded; this results in an under-approximation that is still use

  • Q : Explain the important thing to HTML

    Explain the important thing to HTML document authors.

  • Q : Define Data type Data type : There are

    Data type: There are 8 primitive data types in Java; five of such symbolize numerical types of changeable range and precision - float, double, int, long and short. The remaining three are employed to symbolizing single-bit values (that is, Boolean), s

  • Q : Define Method header Method header : It

    Method header: It is the header of a method, comprising of the method name, its outcome type, formal arguments and any exceptions thrown. Also termed as a method signature.

  • Q : Why do I require TC Trustcenter

    Why do I require TC Trustcenter Publisher ID?

  • Q : What are Logical operators Logical

    Logical operators: The operators, like &&, ||, &, | and ^ which take two Boolean operands and generate a Boolean outcome. Employed as part of a Boolean expression, frequently in the condition of the control structure.