dynamic memory allocation in c++ program code example
Example 1: c++ delet from memory
int* ptr1 = new int;
delete ptr1;
int* array = new int[10];
delete[] array;
Example 2: dynamic memory allocation in c++
char* pvalue = NULL;
pvalue = new char[20];
Example 3: c++ dynamic memory allocation exercises
#include <iostream>
int main()
{
int *ptr = new int;
*ptr = 4;
std::cout << *ptr << std::endl;
return 0;
}
Example 4: dynamic memory allocation in c++
#include <iostream>
using namespace std;
int main () {
double* pvalue = NULL;
pvalue = new double;
*pvalue = 29494.99;
cout << "Value of pvalue : " << *pvalue << endl;
delete pvalue;
return 0;
}