teuntje
asked on
malloc() in c++
I was told malloc() is c and not c++. Is this correct ??
If so, how should I do a malloc() in c++ ?
If so, how should I do a malloc() in c++ ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There is even more:
if you want to allocate or delete an ARRAY you should use this:
char *myArray = new char[number];
to access element 20 use
*myArray[19] = value;
and
delete[] myArray; // DO NOT insert a number here, C++ will handle this internal.
And its correct: c++ DOES accept malloc() and free(), but there is no guarantee (this depends on your compiler -> it works with my Borland Compiler but I prefer new and delete)
best regards
void_main
if you want to allocate or delete an ARRAY you should use this:
char *myArray = new char[number];
to access element 20 use
*myArray[19] = value;
and
delete[] myArray; // DO NOT insert a number here, C++ will handle this internal.
And its correct: c++ DOES accept malloc() and free(), but there is no guarantee (this depends on your compiler -> it works with my Borland Compiler but I prefer new and delete)
best regards
void_main
ASKER
thank you.