---
title: "Dynamic memory allocation in C++"  
description: "Dynamic memory allocation in C++In this blog, I’m explaining about Dynamic memory allocation in C++Allocation:1. Dynamic memory allocation is the allo"  
author: "priyanka kushwaha"  
published: 2015-02-05  
updated: 2015-02-05  
canonical: https://www.mindstick.com/blog/759/dynamic-memory-allocation-in-c-plus-plus  
category: ".net"  
tags: ["visual c++"]  
reading_time: 1 minute  

---

# Dynamic memory allocation in C++

Dynamic [memory allocation](https://www.mindstick.com/forum/159479/what-are-the-differences-between-new-and-malloc-for-memory-allocation-in-c-plus-plus) in [C++](https://www.mindstick.com/blog/745/array-in-c-plus-plus)

In this blog, I’m explaining about [Dynamic memory](https://www.mindstick.com/forum/157955/what-is-dynamic-memory-allocation-in-c-and-how-is-it-used-to-allocate-memory-at-runtime) allocation in C++

Allocation:

1. Dynamic memory allocation is the allocation of memory at “run time”.

2. Dynamically allocated memory is kept on the [memory heap](https://www.mindstick.com/forum/158218/what-is-a-memory-heap-and-how-is-it-used-in-memory-management).

3. Dynamically allocated memory cannot have a “name” it must referred to

4. The new [operator](https://www.mindstick.com/blog/144/union-intersection-and-except-operator-in-sql-server) is used to dynamically allocated memory.

\
De-Allocation

\
1. De-allocation is the “clean-up” of space being used for [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) or other

\

[data storage](https://www.mindstick.com/interview/2601/what-are-different-data-storage-options-are-available-in-android).

\
2. To de-allocation dynamic memory, we use the [delete](https://www.mindstick.com/forum/33620/how-to-delete-record-from-list-in-mvc-using-ajax) operator.

##### Example:

```
// DynamicMemoryAllocation.cpp : main project file.//Create Dynamic Array#include "stdafx.h"#include <iostream>using namespace std;using namespace System; int main(array<System::String ^> ^args){            double* ptr=new double;            int j=0;            cout<<"\nYou want to terminate press '-1'\n";            while(*(ptr+j)!='Q')            {               cout<<"Enter a number";                        cin>>*(ptr+j);                        if(*(ptr+j)==-1)                                    break;                        j++;            }            for(int i=0;i<j;i++)                        cout<<*(ptr+i);       delete ptr;            Console::ReadKey(0);    return 0;}
```

---

Original Source: https://www.mindstick.com/blog/759/dynamic-memory-allocation-in-c-plus-plus

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
