The definitions section of a C program defines the program's variables and constants. Variables may be have a type of int or timer. Constants may be either const int or const string.
Each definition may define one or more token, with commas used to separate the tokens. The format is:
type token1 [ = value ] [ , token2... ] ;
For example:
int i=5, j, k=1000; timer T; const int NUMBER_OF_RETRIES=3, TIMEOUT=10000; const string SUCCESS_MSG="Success!\n";
For variables (type int or timer), the optional value defines the variable's initial value. All variables without initial values will be initialized to 0 when the program starts.
For constants, the value is required.
Variables and constants are named with a token. Tokens can be any combination of letters, digits, and the underscore character ("_"); provided that the token does not begin with a digit. Case is signifigant in C, so the token Value names a different variable than does value.
Constants are traditionally named with all uppercase characters and underscore characters are used to separate words, but this is not required by the IDE.
Integers (type int) and timers (type timer) are represented by 16-bit values. This gives them a potential range of -32768 to 32767. No error is raised if a computation goes out of bounds. The value will just "wrap around" from positive to negative or vice-verse.
Integer constants may be entered in decimal (ex: 123), in hexidecimal (ex: 0xFC), or in octal (ex: 0702).
Strings may be assigned any set of characters as long as they are enclosed in quotes. In addition, the compiler accepts a variety of escape codes to allow you to enter those "hard to reach" characters:
Code | Meaning |
---|---|
\" | Quote (0x22) |
\\ | Backslash (0x5C) |
\n | Carriage-return, line-feed (0x0D, 0x0A) |
\t | Tab (0x09) |
\octal_num | ASCII code |
\xhex_num | ASCII code |