arrays - What is meant by the statement new employee *[num] in C++ -
i came across statement in book.
new employee *[num];
where employee has been declared struct employee , num int;
this on right hand side of = operator on statement.
so, meant statment? book doesn't offer explanation of said statement.
this allocate memory required hold num
number of pointers employee
on free store.
e.g:
employee** = new employee* [2]; // 2 pointers on heap
heap:
address (e.g. 0x97a0008): pointer1 employee address + 1 ( 0x97a000c): pointer2 employee
side note: utilize delete[]
on arrays can delete above delete[] a
but have loop first through entries if have allocated memory them have freed before loose pointer.
http://stackoverflow.com/a/13477214/1141471
c++ arrays pointers new-operator
No comments:
Post a Comment