Allocate memory for objects dynamically in CPP - Memory Management

Q.  Can we allocate memory for the objects dynamically in CPP?
- Published on 19 Jul 15

a. Yes
b. No

ANSWER: Yes
 

    Discussion

  • Nihal   -Posted on 07 Oct 15
    we can allocate memory for the objects dynamically in CPP by using new operator. Dynamically allocated memory placed in a program segment called as heap or free store.
    Example:
    int * p = new int; // dynamic integer, pointed to by p

    *p = 100; // assigns 100 to the dynamic integer
    cout << *p; // prints 100

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)