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.