Knowee
Questions
Features
Study Tools

Which of the following correctly deallocates memory allocated for an array in C++?delete ptr;delete[] ptr;free(ptr);delete array ptr;

Question

Which of the following correctly deallocates memory allocated for an array in C++?delete ptr;delete[] ptr;free(ptr);delete array ptr;
🧐 Not the exact question you are looking for?Go ask a question

Solution 1

The correct way to deallocate memory allocated for an array in C++ is by using delete[] ptr;.

Here's why:

  1. delete ptr; - This is used to delete memory allocated for a single object, not an array. If used on an array, it will only delete the first element, leading to a memory leak.

  2. `dele Knowee AI is a powerful AI-powered study tool designed to help you to solve study problem.

Knowee AI  is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI  is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI  is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI  is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI  

This problem has been solved

Similar Questions

Which of the following correctly deallocates memory allocated for an array in C++?delete ptr;delete[] ptr;free(ptr);delete array ptr;

Which of the following syntax correctly declares an Array in C/C++?int geeks;array geeks[20];geeks{20};int geeks[20];

Which of the following correctly declares an array of 10 integers in C++?int array[10];int array(10);array int[10];array[10] int;

How is memory allocated for an array dynamically in C++?int* arr = new int[10];int arr = new int[10];int arr[10] = new int;int* arr = alloc int[10];

What is the output of the following C code?char *ptr;char mystring[] = "abcdefg";ptr = myString;ptr += 5;

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.