I am here stuck with a question in my C++ book with the following:
“What does the use of new require you to also call delete?”
Maybe you have an answer for that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because that is the way C++ is designed & that is the intended behavior.
The intention was to provide a memory allocation which you demand and own till you reliquish it explicitly.
newgives you a dynamic memory allocation(on heap) which will continue to exist and you own it untill you explicitly deallocate it by callingdelete.Failing to call a
deleteon anewed buffer will leadto Undefined Behaviors usually in the form of. 1 memory leaks.1 This was discussed here.