Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in or
create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision |
Your text |
Line 98: |
Line 98: |
|
| |
|
| Here we define x and initialize y to 10, print y to console, and then set them both to 0 afterwards. | | Here we define x and initialize y to 10, print y to console, and then set them both to 0 afterwards. |
|
| |
|
| |
| Normal variables like the ones we defined above can be changed at any time, however what if we have a variable that we don't want to change or that wouldn't make any sense to change? This is where constants come in.
| |
|
| |
| <syntaxhighlight lang="c" line="1" start="1" style="font-weight:bold;>
| |
| const DAYS_IN_WEEK = 7;
| |
| const PI = 3.1415926535;
| |
| const NAME = "Dell Conagher";
| |
| </syntaxhighlight>
| |
|
| |
| Constants are variables which cannot be changed after they are created, however they can only contain certain values. Constants may only be created with integer, float, or string '''literals'''. We go over what these are in depth in the [https://sigwiki.potato.tf/index.php/Squirrel_Data_Types Data Types] chapter. For now if you'd like a reference of what those are, the variables in the above example contain the specified types. <code>7</code> is an '''integer''', <code>3.14</code> is a '''float''', and <code>"Dell Conagher"</code> is a '''string'''.
| |