Dynamic memory allocation is done using New operator - Memory Management

Q.  In CPP, dynamic memory allocation is done using ______________ operator.
- Published on 19 Jul 15

a. calloc()
b. malloc()
c. allocate
d. New

ANSWER: New
 

    Discussion

  • Nihal   -Posted on 07 Oct 15
    In CPP, dynamic memory allocation is done using new operator.
    Example:
    class Employee
    {
    float salary;
    public:
    Employee()
    {
    salary=0.0;
    }
    Employee(float sal)
    {
    salary=sal;
    }
    void getSal()
    {
    cout << "\n Employee salary= " << salary;
    }
    };
    void main()
    {
    Employee *e=new Employee();
    Employee *obj=new Employee(1000.0);
    obj->getSal();

    }

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.)