0

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;
}
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by bluemm87
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.