title: C++ program freezes randomly for no apparent reason
body: <p>Can someboy explain to me why when I compile this code, sometimes it reaches the "might or mighnot" point, but most of the times it freezes on the "hi" and nothing happens. The program doest make another iteration either. I'm really puzzled; I'm using Code::blocks on Windows as IDE. And this only happens when I set a BigInteger for multiplication >= 100.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;list&gt;
  using namespace std;
  
      class BigInteger
      {
          vector&lt;int&gt; representation;
      private:
          vector&lt;int&gt; truncateZeros()
          {
              int end = 0;
              for(int i = this-&gt;representation.size()-1; i &gt;= 0; --i)
              {
                  if(this-&gt;representation[i] != 0)
                  {
                      end = i;
                      break;
                  }
              }
              vector&lt;int&gt; truncated;
              for(int i = 0; i &lt;= end; ++i)
              {
                  truncated.push_back(this-&gt;representation[i]);
              }
              return truncated;
          }
      public:
          BigInteger(int number)
          {
              this-&gt;representation.resize(100);
              int pos = 0;
              while(number != 0)
              {
                  this-&gt;representation[pos] = number % 10;
                  number /= 10;
                  ++pos;
              }
          }
          BigInteger(string number)
          {
              this-&gt;representation.resize(100);
              int pos = 0;
              for(int i = number.size()-1; i &gt;= 0; --i)
              {
                  this-&gt;representation[pos] = number[i] - '0';
                  ++pos;
              }
          }
          BigInteger(vector&lt;int&gt; number)
          {
              this-&gt;representation.resize(100);
              int pos = 0;
              for(int i = number.size()-1; i &gt;= 0; --i)
              {
                  this-&gt;representation[pos]=number[i];
                  ++pos;
              }
          }
          vector&lt;int&gt; getInteger()
          {
              vector&lt;int&gt; copy;
              vector&lt;int&gt; truncated = this-&gt;truncateZeros();
              copy.resize(truncated.size());
              std::copy(truncated.begin(), truncated.end(), copy.begin());
              reverse(copy.begin(), copy.end());
              return copy;
          }
          string toString()
          {
              string result;
              vector&lt;int&gt; truncated = this-&gt;truncateZeros();
              for(int i = truncated.size()-1; i &gt;= 0; --i)
              {
                  result.push_back(truncated[i] + '0');
              }
              return result;
          }
          BigInteger multiplyBy(BigInteger bigNumber)
          {
              vector&lt;int&gt; bigNum = bigNumber.getInteger();
              vector&lt;int&gt; sum(this-&gt;representation.size());
              int size = bigNum.size();
              for(int j = 0, i = size-1; i &gt;= 0; --i, ++j)
              {
                  int desetici = 0;
                  vector&lt;int&gt; result(this-&gt;representation.size());
                  int startAt = 0;
                  for(int k = 1; k &lt;= j; ++k)
                  {
                      ++startAt;
                  }
                  for(int k = 0; k &lt; this-&gt;representation.size(); ++k)
                  {
                      int res = this-&gt;representation[k] * bigNum[i];
                      if(desetici &gt; 0)
                      {
                          res += desetici;
                          desetici = 0;
                      }
                      if(res &gt; 9)
                      {
                          result[k + j] = res % 10;
                          res /= 10;
                          desetici = res % 10;
                      }
                      else
                      {
                          result[k + j] = res;
                      }
                  }
                  //now sum
                  for(int k = 0; k &lt; result.size(); ++k)
                  {
                      sum[k] += result[k];
                      int pos = k;
                      while(sum[pos] &gt; 9)
                      {
                          ++sum[pos+1];
                          sum[pos] = sum[pos] % 10;
                          ++pos;
                      }
                  }
                  cout&lt;&lt;"hi"&lt;&lt;endl;
              }
              cout&lt;&lt;"Might or might not";
              //now we return sum
              reverse(sum.begin(), sum.end());
              return BigInteger(sum);
  
          }
      };
      int main()
      {
          int a = 10000;
          BigInteger big = BigInteger(a);
          vector&lt;int&gt; rep = big.getInteger();
          for(int i = 0; i &lt; rep.size(); ++i)
          {
              cout&lt;&lt;rep[i];
          }
          cout&lt;&lt;endl;
          string asResult = big.toString();
          cout&lt;&lt;asResult&lt;&lt;endl;
          cout&lt;&lt;"Try to multiply:"&lt;&lt;endl;
          BigInteger res = big.multiplyBy(BigInteger(876));
          string aaa = res.toString();
          cout&lt;&lt;aaa;
          return 0;
      }
  </code></pre>