Variables and Constants

Hilko Janssen edited this page Oct 29, 2018 · 1 revision

Variables

To initiate a variable you simply use the <var> tag.

<var myVariable=10/>

This will initiate an integer with the value 10.

C-code:

int myVariable = 10;

Types

Variables have types, by using the type attribute you can define what type the variable should be.

<var myVariable="47884" type="unsigned int" />

C-code:

unsigned int myVariable = 47884;

If you do not provide a type attribute, the compiler will try to guess what type you meant.

<var myVariable=10/>

Will be seen as int, because 10 is not wrapped in quotes.

<var myVariable='b'/>

Will be seen as char, because 'b' is wrapped in single quotes.

<var myVariable="hello mario"/>

Will be seen as string (char*), because "hello mario" is wrapped in double quotes.

If the compiler cannot guess the variable type, it will say your code sucks and then you need to provide a type attribute.

Constants

Constants are like variables but instead of being variable, constants are constant, you cannot change them. To create a constant you use a <const> tag, which works exactly the same as the <var> tag.

<const myConstant=10/>

C-code

static const myConstant = 10;
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.