user40485: I made a counter to count pulses:
int count  = 0 ;
.
.
.
setup()
{    
}    

while (count <= 35000)
{    
  digitalWrite(9, HIGH);
  delayMicroseconds(500);
  digitalWrite(9, LOW);

  count = count + 1;
}

But when I try while(count <= 40000), it does not stop counting.

user19409: You have reached the maximum number that an int can represent. That is 32767.
int is a variable type that is made up of 16 bits. It is signed, meaning that it can represent positive and negative numbers.
Out of the 65536 (ie. 2^16) possible numbers from the 16 bits, half of them represent negative numbers and the remaining half represents positive numbers (including zero). Or in other words, -32768 to 32767.
If you don't need negative numbers, then you can change your variable type to unsigned int which  will use numbers up to a maximum of 65535. So it becomes:
unsigned int count = 0;


user368: int in AVR GCC is 16 bits. All possible int values are less than 32767.

40485: <p>I made a counter to count pulses:</p>

<pre class="lang-cpp prettyprint-override"><code>int count  = 0 ;
.
.
.
setup()
{    
}    

while (count &lt;= 35000)
{    
  digitalWrite(9, HIGH);
  delayMicroseconds(500);
  digitalWrite(9, LOW);

  count = count + 1;
}
</code></pre>

<p>But when I try <code>while(count &lt;= 40000)</code>, it does not stop counting.</p>
 19409: <p>You have reached the maximum number that an <code>int</code> can represent. That is <strong>32767</strong>.</p>

<p><code>int</code> is a variable type that is made up of <strong>16 bits</strong>. It is <strong>signed</strong>, meaning that it can represent positive and negative numbers.</p>

<p>Out of the <strong>65536</strong> (ie. <strong>2^16</strong>) possible numbers from the 16 bits, half of them represent negative numbers and the remaining half represents positive numbers (including zero). Or in other words, <strong>-32768 to 32767</strong>.</p>

<p>If you don't need negative numbers, then you can change your variable type to <code>unsigned int</code> which  will use numbers up to a maximum of <strong>65535</strong>. So it becomes:</p>

<pre><code>unsigned int count = 0;
</code></pre>
 368: <p><code>int</code> in AVR GCC is <a href="https://gcc.gnu.org/wiki/avr-gcc#Type_Layout" rel="nofollow noreferrer">16 bits</a>. <strong><em>All</em></strong> possible <code>int</code> values are less than 32767.</p>
