Out-of-memory warning and out-of-memory warning

Source: Internet
Author: User

Out-of-memory warning and out-of-memory warning

Run-Time Check Failure #2-Stack around the variable '******' was upted. Warning

Problem:

/*
* 30 random numbers are generated, and 10 rows are output. Find the prime number and output it.
*/

The code for generating a random number is as follows:

// Random number generation module;
Int intArray [30]; // defines an integer array intArray [] to store the thirty random numbers;
Int I; // defines a global variable I for recycling;
For (I = 1; I <= 30; I ++)
/* The problem lies in the simhei part.

*/

{
IntArray [I] = (rand () % (1000-100) + 100; // random number generated by cyclic storage;
}
Printf ("30 random numbers generated are as follows: \ n"); // print a sentence;
For (int I = 1; I <= 30; I ++) // use the local variable I to output this array;
{
Printf ("% 5d", intArray [I]);
If (I % 10 = 0) // Add a judgment condition so that only 10 numbers are output in each row;
{
Printf ("\ n ");
}

Eg:
Int a [30];
For (int I = 1; I <= 30; I ++)
{
A [I] = ranf () % 100;
}
In this way, small enough space is defined, which saves the Space Value and reduces the memory demand. However, an out-of-boundary warning will appear after the program runs for 30 cycles,
The simplest way to eliminate such warnings is to make the defined array space large enough, at least not to conflict with the number of cycles.

Modify

Eg:

Int a [31];

For (int I = 1; I <= 30; I ++)

{

A [I] = rand () %100;

}

// The defined interval must always be larger than the expected interval, eliminating the warning.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.