C++ hangUp after removing unused variables -
This simple code is introduced in Dev ++++++++++++++++++++++++++ Code> a is not used. After I remove them or comment, hang the program. Why?
#include & lt; Iostream & gt; #include & lt; Vector & gt; using namespace std; #define N 10 * 1000 * 1000 bool p [N]; Int f [n], a [n]; Of vector & lt; Int & gt; Prime number; For int (i) (int i = 2; i & lt; = n; i ++) if (! P [i]) {for (int j = i; j & lt; = n; j + = i ) P [j] = true; // or = 1 primes.push_back (i); } System ("PAUSE"); Return EXIT_SUCCESS; }
You are reading / writing after the limit of P Sir.
In the memory, after the P [N] array F [N] array, then [N] array arrives.
So when you're trying to write P [N], actually the F will be written [0].
When you remove F and an array, you will write something from the vector & lt; Int> primes
My guess is that vector is a square so that you make some important screws when your code will be stationed at Jammu == n, at the bridge_back call.
Comments
Post a Comment