Which of the following correctly deallocates memory allocated for an array in C++?delete ptr;delete[] ptr;free(ptr);delete array ptr;
Question
Solution 1
The correct way to deallocate memory allocated for an array in C++ is by using delete[] ptr;
.
Here's why:
-
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. -
`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
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;
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.