Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the important memory allocation flaw that is seen here?
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COYou clearly put no effort into this. If you took 10 seconds to type in "C++ new" into google you would of immediately found advice about having one `delete` for every corresponding `new` and one `delete[]` for every corresponding `new[]` and not mixing them. Missing homework tag. Homework requires you to put in some effort, not to simply repost the question.
      singulars
    2. CO@Preet No need to take "that 10 seconds". I know that every new needs a delete and every new[] neds a delete[]. But the thing here is I did not understand the question. Thanks to Luchian Grigore, I understood the question properly only after reading his answer. And about the 'homework' tag; as I recently joined here, I did not know that there is a 'homework' tag. Anyway thanks for the information
      singulars
    3. COI would presume that if you already "know" about `new` and `delete`, you would also have investigated what they actually do beyond syntax and have a basic idea of how they function (heap allocation), and hence how heap allocation differs from stack allocation/auto variables in usage and requirements. Might as well add here that in practical C++, you would almost never have a function like the one in the question (you would either use stack variable or pass a value in by reference or pointer if you need to modify it in the calling scope, or pass by value if you just want to print)
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload