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;
}

A typo has slipped in ... it should be localVariable .

thanks :) i should have proof read a third time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.