Dynamic memory allocation

xiaoxiao2021-03-05  21

New and delete

1.new

Usage: Pointer to the corresponding type of pointer = new type descriptor

a. A machine word length

INT * P;

P = new int;

b. A machine word length, and assign

INT * P;

P = new int (20);

c. Multiple words long, press array or pointer reference

INT * P;

P = new int [20];

2.delete

Usage: delete pointer name

The pointer is an array, and it is also possible to add "[]" before the pointer name.

Delete [n] pointer name

转载请注明原文地址:https://www.9cbs.com/read-32306.html

New Post(0)