title: C++: same code and compiler, but different output after each build
body: <p>Greetings to StackOverflow's community! I seriously need someone's help. <br>
  Here is my code that is supposed to print two integers, which are the first and the last indexes of the shortest sentence's symbols in the string given (str).
  As you can see, the shortest sentence in this string is "Hey!!!"; character 'H' has index 16 and the last exclamation mark has index 21, so correct output should be: 16 21. <br>
  I've compiled my code using CppShell (cpp.sh) and here's the deal: same code compiled with the same compiler gives different result at each new attempt to build it: <br><br>
  Attempt #1: 16 21 <br>
  Attempt #2: 145921712 4196790 <br>
  Attempt #3: 16 21 <br>
  Attempt #4: 16 21 <br>
  Attempt #5: 1453219648 4196790 <br>
  etc.<br><br>
  Could someone please explain me this strange situation? I'm novice at C++, therefore I may not see some obvious mistakes in my code.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;clocale&gt;
  #include &lt;cstdio&gt;
  #include &lt;cstring&gt;
  
  using namespace std;
  
  int main()
  {
      setlocale(LC_CTYPE, "rus");
  
      char str[] = "     What's up? Hey!!!    It's a practice... How are you??    ";
      char* ptr = str;
      char* p = ptr;
  
      int startsym, endsym;
      int startsymMin = 0, endsymMin = 2000; 
  
      while(*ptr)
      {
          if (*ptr &gt; 64 &amp;&amp; *ptr &lt; 91) // capitalized letters 'A'-'Z'
          {
              startsym = strchr(ptr, *ptr)-p;
  
              while(*ptr)
              {
                  if ((*ptr == '!' &amp;&amp; *(ptr+1) != '!' &amp;&amp; *(ptr+1) != '?')
                      || (*ptr == '?' &amp;&amp; *(ptr+1) != '!' &amp;&amp; *(ptr+1) != '?')
                      || (*ptr == '.' &amp;&amp; *(ptr+1) != '.'))
                  {
                      endsym = strchr(ptr, *ptr)-p;
                      break;
                  }
                  ptr++;
              }
          }
  
          if (endsym - startsym &lt; endsymMin - startsymMin) {
              startsymMin = startsym;
              endsymMin = endsym;
          }
  
          ptr++;
      }
  
      cout &lt;&lt; startsymMin &lt;&lt; " " &lt;&lt; endsymMin &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>