In this program
int main() {
// Will this code cause memory leak?
// Do I need to call the free operator?
// Do I need to call delete?
int arr[3] = {2, 2, 3};
return 0;
}
array arr
is a local variable of function main with the automatic storage duration. It will be destroyed after the function finishes its work.
The function itself allocated the array when it was called and it will be destroyed afetr exiting the function.
There is no memory leak.
You shall not call neither C function free nor the operator delete [].
If the program would look the following way
int main() {
int *arr = new int[3] {2, 2, 3};
//...
delete [] arr;
return 0;
}
then you should write operator delete [] as it is shown in the function.