--%>

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 : Features and advantages of UNIX Specify

    Specify the features and advantages of the UNIX?

  • Q : Ways to select HTML Tag Instances

    Explain the different ways in order to select the HTML Tag Instances.

  • Q : Problem on three dimensional diagram of

    Create a three dimensional diagram of function z = (x-2)2 + (y-3)3.

  • Q : Explain script recorded over tested web

    Why is the script recorded over the tested web pages not playback correctly?

  • Q : Ways in which Java program is less

    Give two ways in which a Java program is less likely to be compromised than the same program written in C++.

  • Q : One-time signature scheme Define

    Define one-time signature scheme?

  • Q : Requirement of Timer control in AJAX

    Explain the requirement of a Timer control in the AJAX.

  • Q : State term System call executable

    State the term System call executable binary file in a process.

  • Q : Use of setjmp and longjmp Use of

    Use of setjmp() and longjmp(): In C/C++, setjmp() saves the contents of the registers at a particular state in the program and longjmp() will restore that state later. In this way, longjmp() “returns” to the state of the program when setjm

  • Q : Reference variables Reference variable

    Discover Q & A

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

    18,76,764

    1941964
    Asked

    3,689

    Active Tutors

    1435929

    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.