--%>

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 : Differences between primary storage and

    What are the differences between primary storage and secondary storage?

  • Q : State the term XPath State the term

    State the term XPath?

  • Q : Define Java 2 SDK Java 2 SDK : It is a

    Java 2 SDK: It is a particular implementation of the abstract functionality explained in Sun's specification of Java 2 Platform.

  • Q : Define TCP endpoint TCP endpoint : It

    TCP endpoint: It is the combination of an IP address and Transmission Control Protocol (abbreviated as TCP) port number.

  • Q : Explain the benefits of distributed

    Explain the benefits of distributed systems.

  • Q : Explain Dynamic Language Runtime

    Explain Dynamic Language Runtime (DLR) briefly?

  • Q : What is Process Process : It is an

    Process: It is an individual thread-of-control to which an execution time slice is assigned by the operating system.

  • Q : Explain Coupling Coupling : Coupling

    Coupling: Coupling occurs whenever classes are aware of each of other as their instances should interact. The linkage between two classes which might be either weak or strong. Stronger coupling occurs whenever one class has a thorough knowledge of the

  • Q : Define the term Nested class Define the

    Define the term Nested class:  It is a class stated within an enclosing class.

  • Q : File handling modes and corresponding

    Discover Q & A

    Leading Solution Library
    Avail More Than 1447338 Solved problems, classrooms assignments, textbook's solutions, for quick Downloads
    No hassle, Instant Access
    Start Discovering

    18,76,764

    1941044
    Asked

    3,689

    Active Tutors

    1447338

    Questions
    Answered

    Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!

    Submit Assignment

    ©TutorsGlobe All rights reserved 2022-2023.