title: cin erratic behaviour
body: <p>I'm a newbie to C++.  Small code sample follows:</p>
  
  <pre><code>int main(int argc, char* argv[]) {    
  
      char ch1;
      int int1;
  
      cin &gt;&gt; ch1;
      cin &gt;&gt; int1;
  
      cout &lt;&lt; ch1 &lt;&lt; '\n';
      cout &lt;&lt; int1 &lt;&lt; '\n';
  
      return 0;
  }
  </code></pre>
  
  <p>When I run the program and input the following:</p>
  
  <blockquote>
    <p>az</p>
  </blockquote>
  
  <p>I get as output:</p>
  
  <blockquote>
    <p>a
    32767</p>
  </blockquote>
  
  <p>I understand the 'a' but why the integer value of 32767?  I just want to test and see what happen if instead of a numeric value assigned to int1 i used a 'z'.</p>
  
  <p>I try inputting:</p>
  
  <blockquote>
    <p>ax</p>
  </blockquote>
  
  <p>...and I also get same results.</p>
  
  <p>Now if instead of <code>int int1</code> I use <code>short int1</code> and run the program with input:</p>
  
  <blockquote>
    <p>az</p>
  </blockquote>
  
  <p>I get the output:</p>
  
  <blockquote>
    <p>a
    0 </p>
  </blockquote>
  
  <p>P.S.</p>
  
  <pre><code>sizeof(int) = 4
  sizeof(short) = 2
  </code></pre>
  
  <p>I am using a 64-bit machine.</p>