I am new to C++ and I have something unclear:
#include <iostream>
using namespace std;
double* foo(void)
{
double* b = new double[100];
return b;
}
int main()
{
double* a = foo();
delete [] a;
return 0;
}
Is there something wrong with this code? I mean whether the way I use operator delete is right? I assign the pointer b which points to the allocated memory in foo function to pointer a outside foo, can I release memory by means of delete[]a in main? I don't have any idea how does the compiler calculate the number of bytes to release when execute delete[]. Thanks