tut2: defining your variables

this is a simple, yet important concept:

variables must be defined before use, and it attributes the amount of data they'll use, and hoe they'll be treated by the compiler.

this is a quick run-down of all of them, Â and will still explain them as they're used in future tutorials

int - as in integer, a number that ranges from -32768 to 32767 these numbers should be familiar to any GM user.

thats because both int, and the standard numerical variable on GM use two bytes of information to stare the data. int stands for integer.

unsigned - the same as integer, but it can only be positive (or zero) to the range is farther 0 - 65535 is also a modifyer

char - a character value that is stored in the computers information as ASCII, and therefore we can use mathematical expressions on it.

it only hold one character

float - as in floating point integer. can also be expressed as double which gives it "double accuracy" and long(explained below)

short/long - these are modifiers, so you would write short or long before int, unsigned, or float

for int it'd be -21474836 to 21474835 it only allocates two more bytes of data(4 total) and the increase is so large because it's expressed in binary which is in base 2, and exponentially based (<<you shouldn't understand that cocept yet. I'll explain it at the bottom of this) exponential

for short is the default

signed - also a default it's for int, float, and double

part2:

assigning variables:

you assign them with the assignment operator '='

one of two ways

`int x; Â //allocated`

x = 5;//initiallized

x was allocated, and then initialized. Â two things I'd like to mention

â€¢those semicolons mark the end of the line, I'll talk more about them in the next tutorial

â€¢'//' is the character for comment, everything after that isn't read by the compiler. exactly like the REM command in GM

also know as the comment command or, "that little apostrophe thingy"

second way is all in one line

does the same thing, I think you can work it out

these do the same thing since k is read as 107 (it's ASCII value)

`char c1 = 'k';`

char c2 = k;

the first statement works and the second doesn't

this is technically sorest, but is a very bad programming practice. it will set c to 'k' then to 'l' and then to 'm'

only one at a time so therefore c would equal m (if your reading the book I mentioned along with my tutorial you will notice that this isn't mentioned in the book.

my work is both consistent, and inconsistent with his work)

`signed short int x1;`

int x2;

these would be of the same data type, and allocate the same memory.

just an example to reiterate the default

`int x, c, v, b;`

x = c = v = b = 0;

did I just blow your mind? two new concepts

â€¢you can declare multiple variable via the comma operator

â€¢you can initialize multiple variables, it is important the zero is on the right side since the assignment operator (=)

evaluates right to left.

this sets b to zero v to b (which is 0) and soforth

`int x = 0, c = 0, v = 4, b;`

this sets x to zero c to zero and v to 4.

b is set the the nearest data address, which may or may not be zero. it's just left over data in the computers memory. if it's a spot in the memory never been use then yes, it could be zero,

but you have no way of knowing it. don't gamble on using uninitilized variables.

part3:

different bases

ADVANCED TOPIC ALERT

65

this number was expressed in base 10, decimal form

0xAE4

this is also a number, but expressed in base 6, hexadecimal form

0177

base 8 octal form

these can all be written to the integer variable type, if you haven't studied exponents then leave now (I don't mean to be rude, but

if you don't already know that this'll demoralize you from learning C/C++)

hexadecimal numbers always start with 0x Â (thats a zero)

so 0x54 is hexadecimal. To find the number you take the digits to powers of 16 (8 for octal, and 10 for decimal)

example:

0x54

5 X 16^1 + 4 X 16^0

remember anything to the power of zero is one

each digit of hex form can be 0 - f, or 0 - F (a number has to have all the "letters" in the same case)

numbers being themselves.

A - 10

B - 11

C - 12

D - 13

E - 14

F - 15

octal is the same followed by a zero, and numbers 0-7

and although we don't thing about it decimal form is the same

123

1 X 10^2 + 2 X 10^1 + 3 X 10^0

I sometime use hex form for writing large numbers, but rarely.

P.S. if you haven't already noticed I'll be making GM comparisons since the languages are similar to help GM programmers get a leg up on C programming. Â

good luck

P.P.S it said it was too long so I had to do it in two posts