user41798: Why can't i assign the value to a variable  outside the function?
void setup(){}
int a;
a=12;   //  WHY IS THIS GIVING ME ERROR
void loop(){
}

Why the line a=12 gives me an error?
Thanks!

user4143: 
a=12;   //  WHY IS THIS GIVING ME ERROR

Because you can't do assignments like that outside of a function.
You can, though, create and assign the variable at the same time:
int a = 12;

That is a declaration of the variable, whereas 
a = 12;

is a procedural statement. Procedural statements cannot be executed in the global scope. They can only be executed inside a function during the execution of the program (the global scope never gets executed).

41798: <p>Why can't i assign the value to a variable  outside the function?</p>

<pre><code>void setup(){}
int a;
a=12;   //  WHY IS THIS GIVING ME ERROR
void loop(){
}
</code></pre>

<p>Why the line <code>a=12</code> gives me an error?
Thanks!</p>
 4143: <blockquote>
  <p>a=12;   //  WHY IS THIS GIVING ME ERROR</p>
</blockquote>

<p>Because you can't do assignments like that outside of a function.</p>

<p>You can, though, create <em>and</em> assign the variable at the same time:</p>

<pre><code>int a = 12;
</code></pre>

<p>That is a declaration of the variable, whereas </p>

<pre><code>a = 12;
</code></pre>

<p>is a procedural statement. Procedural statements cannot be executed in the global scope. They can only be executed inside a function during the execution of the program (the global scope never gets executed).</p>
