Original Post
Hello, I'm new to this forum, and I'm just starting in C++. I've had some experience (sort of) programming in Game Maker, so I've got a good grasp on basic things like variables, arrays, loops and stuff like that. Recently, however, I've been having some problems with pointers (hence the topic title); I've been trying to use them to create a dynamically sized array, and it seems to be working pretty well, except my program freezes at seemingly random times. I'm pretty sure it's a memory leak, but I'm not too good at finding those things. Here's the source code for my program; any help would be appreciated. If it helps, I'm using Dev-C++ 4.9.9.2.
Edit by Fruny: re-fixed the formatting. [Edited by - Fruny on August 10, 2006 12:51:47 AM]
#include <iostream>
using namespace std;
int main()
{
long int input;
long int i;
while(true)
{
cin >> input;
long int *pointer = new long int[input];
for(i=0;i<=input;i+=1)
{
pointer=i;
}
cout << pointer[input] << "\n";
cin.get();
delete [] pointer;
cout << "Memory cleared.\n";
cin.get();
system("cls");
}
cin.get();
} P.S.: If anyone knows how I could put my code in a box on this forum, to separate it from the rest of my post, I'd greatly appreciate it if you could tell me. EDIT: Don't bash me for the lack of indentation, the forum decided to get rid of mine when I posted :P EDIT2: After some testing, I've found out that it wasn't really random freezing, it was only freezing after I typed numbers while pressing enter really fast, or if I typed numbers over 100,000,000. Might not be a leak after all, just me being stupid and overestimating my console app. :O Edit by Fruny: re-fixed the formatting. [Edited by - Fruny on August 10, 2006 12:51:47 AM]