#include <iostream>
int main()
{
int localVariable = 5;
int * intPointer= &localVariable;
int * heapPointer = new int;
if (heapPointer == NULL)
{
std::cout << "Error! No memory for heapPointer!!";
return 1;
}
*heapPointer = 7;
std::cout << "localVariable: " << localVariable << "\n";
std::cout << "*intPointer: " << *intPointer << "\n";
std::cout << "*heapPointer: " << *heapPointer << "\n";
delete heapPointer;
heapPointer = new int;
if (heapPointer == NULL)
{
std::cout << "Error! No memory for heapPointer!!";
return 1;
}
*heapPointer = 9;
std::cout << "*heapPointer: " << *heapPointer << "\n";
delete heapPointer;
return 0;
}
|