Memory in C++ is divided into two categories: stack and heap.
Variables created at compile time are stored in the stack. The stack has a fixed size determined by the computer. When variable is no longer used, the stack is released.
Function arguments and return locations are stored on the stack.
Memory not used by the Operating System or programs is called the heap, sometimes referred to as the free store.
Heap can be used for dynamic variable creation. We can use new operator to request the space. The new operator returns the address of the space.
The complement operator of new is delete operator, which releases memory that we previously allocated.
Arrays can take up a lot of space, so we can use new and delete operator to create and delete it on demand.
#include"stdafx.h"#include<iostream>usingnamespace std;intmain(){int*pointer(newint(55));// create a new integer variable that doesn't have a variable name
cout <<*pointer << endl;delete pointer;int*pArray(newint(5){10,20,30,40,50});*(pArray +1)+=5;
cout <<*pArray <<", "<<*(pArray +1)<< endl;delete pArray;return0;}