Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


CRT detected that the application wrote to memory after end of heap buffer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 bjorn88   Members   -  Reputation: 100

Like
0Likes
Like

Posted 11 October 2010 - 11:47 AM

I just wrote a simple program to test my new knowledge of allocating memory and of course deleting the allocated memory. However, when I run my program I get this strange error. Here's my code:


int main(){

int a = 0;

std::cout << "Enter array size: ";
std::cin >> a;

int* myArray = new int[a];

for (int i=0;i<=a;i++){
myArray[i] = i;
std::cout << myArray[i];
}

delete[] myArray;
myArray = 0;

std::cin.get();

}




Sponsor:

#2 KulSeran   Members   -  Reputation: 2563

Like
0Likes
Like

Posted 11 October 2010 - 11:51 AM

Quote:

for (int i=0;i<=a;i++)

Your array only takes up the range [0,a). You need to write your loop as
for( int i=0; i<a; i++ )

You were writing one past the end of the array.

#3 bjorn88   Members   -  Reputation: 100

Like
0Likes
Like

Posted 11 October 2010 - 11:58 AM

Quote:
Original post by KulSeran
Quote:

for (int i=0;i<=a;i++)

Your array only takes up the range [0,a). You need to write your loop as
for( int i=0; i<a; i++ )

You were writing one past the end of the array.


Hey, thanks very much! I guess it was something simple after all.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS