18 lines
1.1 KiB
HTML
18 lines
1.1 KiB
HTML
|
<p>
|
||
|
Variables are used to store values. Basically you have a <b>storage location</b> with a <b>name</b> and an <b>associated type</b>.
|
||
|
The compiler will check, if the value you assign to the variable is from the same type as the variable.
|
||
|
If not, it will throw an error.
|
||
|
</p>
|
||
|
<p>
|
||
|
That is because C is a <b>statically type checked language</b>. Dynamically type checked languages may let you use your variables more freely,
|
||
|
but will also hide bugs, which can produce unpredictable results. It is a small price to pay, to
|
||
|
build a more robust code, which is immune to this kind of bugs, if you don't miss use type casting.
|
||
|
</p>
|
||
|
<p>
|
||
|
Because variables just refer to a space in memory, you can easily change the value to a new one.
|
||
|
The thing that you can't change is the type.
|
||
|
Sometimes you just want to have a name for a constant value. In C you can use the <b>const</b> keyword to declare
|
||
|
a variable as constant, i.e you cant change the value once it is assigned.
|
||
|
If you know the value isn't supposed to change, you should declare it const to prevent bugs, which you could be a pain to find.
|
||
|
</p>
|