The below code works fine on ideone, gives an output of
10000
10000
as expected
However on my local machine, the output is of the sort
9990
9998
All the code does is create a vector of 10k int
's and count the number of 0's in it. Once using a class, and once in main.
If I run the code locally in debug mode, it results in
0
0
I'm using codeBlocks on Windows 7 with the default GNU GCC Compiler (though it compiles C++, so I guess its different than the Linux GCC which does only C)
#include<iostream>
#include<vector>
using namespace std;
class vecttest
{
vector<int> vect;
public:
vecttest()
{
vect.reserve(10000);
}
int zcount()
{
int count=0;
for(int i=0;i<10000;i++)
{
if(vect[i]==0)
count++;
}
return count;
}
};
int main()
{
vecttest v;
cout<<v.zcount();
vector<int> v2;
v2.reserve(10000);
int count=0;
for(int i=0;i<10000;i++)
{
if(v2[i]==0)
count++;
}
cout<<endl<<count;
}
ideone link: http://ideone.com/q1XRvQ