Skip to main content

Posts

Showing posts with the label Dynamic allocation

Dynamic allocation

Dynamic allocation Why And How  In many situations the programmer does not know when he writes a program what objects he will need. It can be that he does not know if he will need a given object, or or that he does not know the size of a required array. The new operator allows to create an object at run-time. This operator takes as an operand a type, which may be followed either by a number of elements between [ ] or by an initial value between ( ) : char *c = new char; int *n = new int(123); double *x = new double[250]; The area of memory allocated by new is still used out of the pointer’s scope!