I'm trying to learn C++ with a book and it has this example program in it, but when i try to compile it, it comes back with error C2065: 'localVarable' : undeclared identifier. What's wrong with it?
// allocating and
// deleting a pointer
#include <iostream>
int main()
{
int localVariable = 5;
int * pLocal= &localVarable;
int * pHeap = new int;
if (pHeap == NULL)
{
std::cout << "Error! No memory for pHeap!!";
return 1;
}
*pHeap = 7;
std::cout << "localVariable: " << localVariable << "\n";
std::cout << "*pLocal: " << *pLocal << "\n";
std::cout << "*pHeap: " << *pHeap << "\n";
delete pHeap;
pHeap = new int;
if (pHeap == NULL)
{
std::cout << "Error! No memory for pHeap!!";
return 1;
}
*pHeap = 9;
std::cout << "*pHeap: " << *pHeap << "\n";
delete pHeap;
return 0;
}