Originally posted by DramaKing
C don't have 'new' and 'delete' , right?
I'm sorry to ask C instead of C++ here..... I don't know it since u guys said it's C.... but can u help me here for this question only? thx!!
I know there are new in C++..........
but when we need it??? As I don't know when there are Segmentation fault if not to use malloc, and I'm worry about memory leakage if forget free the memory.
Thanks!!~
Code:
int main()
{
int* Array; //Create pointer
Array=new int[256]; //Allocate memory for 256 ints
if(Array!=NULL) //Checks if allocation was successful, if not the pointer has the value NULL
{
//Whatever you want to do with the array...
delete[] Array; //Deallocate memory, but only if it has been allocated first. Otherwise it might crash...
}
return 0;
}