user6834: I read definitions like
const int ledPin = 9;

and also
#define ledPin 9

I know that a definition like
int ledPin = 9;

is a bad practice if you're not going to change it (which you usually won't), though I've see this several times in Arduino programs.
Which one of the other two is preferred?

user8711: Probably the best way would be
const uint8_t LED_PIN = 9; // may require to #include <stdint.h>
    or
const byte LED_PIN = 9; // with no include necessary
const unsigned char LED_PIN = 9; // similarly
The name is in caps as per general practice in C++ (and others) to name constants. 
This should not use any RAM in itself, and use about 1 byte of program memory per use.
However, there might be problems when the number is higher than 127 and is sign-extended while getting promoted to larger signed integers (not entirely sure on this), although that is unlikely to happen with pin numbers.

user42: Strictly speaking, the #define approach will use slightly less memory. The difference is usually tiny though. If you need to reduce memory usage, then other optimisations would probably be far more effective.
An argument in favour of using const int is type safety. Wherever you refer to that pin number by variable, you know exactly what data type you're getting. It might be promoted/converted implicitly or explicitly by the code which uses it, but it should behave in very clear ways.
By contrast, the value in a #define is open to interpretation. The vast majority of the time, it probably won't cause you any problems at all. You just need to be a little careful if you have code which makes assumptions about the type or size of the value.
Personally, I almost always prefer type safety unless I have a very serious need to save memory.

user-1: #define ledPin 9 is preferred. By doing int ledPin = 9; you will be allocating an int memory whose value is used every time you use ledPin. #define is different in the sense it doesn't allocate memory. there is no memory called ledPin. Before compiling all "ledPin"s in the code(other than strings) are replaced by 9. So basically 
digitalWrite(ledPin);

becomes
digitalWrite(9);

Advantages of #define : Saves memory and since all ledPin are replaced by 9 before execution, it saves processor time. 
Doesn't really matter in small codes...

6834: <p>I read definitions like</p>

<pre><code>const int ledPin = 9;
</code></pre>

<p>and also</p>

<pre><code>#define ledPin 9
</code></pre>

<p>I know that a definition like</p>

<pre><code>int ledPin = 9;
</code></pre>

<p>is a bad practice if you're not going to change it (which you usually won't), though I've see this several times in Arduino programs.
Which one of the other two is preferred?</p>
 8711: <p>Probably the best way would be<br>
    <code>const uint8_t LED_PIN = 9; // may require to #include &lt;stdint.h&gt;</code><br>
    or<br>
    <code>const byte LED_PIN = 9; // with no include necessary</code><br>
    <code>const unsigned char LED_PIN = 9; // similarly</code><br>
The name is in caps as per general practice in C++ (and others) to name constants. 
This should not use any RAM in itself, and use about 1 byte of program memory per use.<br>
However, there <em>might</em> be problems when the number is higher than 127 and is sign-extended while getting promoted to larger signed integers (not entirely sure on this), although that is unlikely to happen with pin numbers.</p>
 42: <p>Strictly speaking, the <code>#define</code> approach will use slightly less memory. The difference is usually tiny though. If you need to reduce memory usage, then other optimisations would probably be far more effective.</p>

<p>An argument in favour of using <code>const int</code> is <strong>type safety</strong>. Wherever you refer to that pin number by variable, you know exactly what data type you're getting. It might be promoted/converted implicitly or explicitly by the code which uses it, but it should behave in very clear ways.</p>

<p>By contrast, the value in a <code>#define</code> is open to interpretation. The vast majority of the time, it probably won't cause you any problems at all. You just need to be a little careful if you have code which makes assumptions about the type or size of the value.</p>

<p>Personally, I almost always prefer type safety unless I have a very serious need to save memory.</p>
 -1: <p><code>#define ledPin 9</code> is preferred. By doing <code>int ledPin = 9;</code> you will be allocating an <code>int</code> memory whose value is used every time you use <code>ledPin</code>. <code>#define</code> is different in the sense it doesn't allocate memory. there is no memory called <code>ledPin</code>. Before compiling all "ledPin"s in the code(other than strings) are replaced by <code>9</code>. So basically </p>

<pre><code>digitalWrite(ledPin);</code>
</pre>

<p>becomes</p>

<pre><code>digitalWrite(9);
</code></pre>

<p>Advantages of <code>#define</code> : Saves memory and since all <code>ledPin</code> are replaced by <code>9</code> <strong>before execution</strong>, it saves processor time. <p>
Doesn't really matter in small codes...</p></p>
