You are here

Assignment

We can copy information into variables:

how_many_cats = 14;

We can copy the information in one variable into another:

how_many_tails = how_many_cats;

We use a single equal sign to indicate that the variable on the left gets changed to the value stored in the variable on the right. Nothing happens to the information in the variable on the right (it does not change or get lost anywhere).

If we put a value from an 8 bit integer variable into a 16 bit integer variable, it fits just fine and all is well.

If we put a value from a 16 bit variable into an 8 bit variable, only the low 8 bits get stored. The high 8 bits are ignored. Thus the expression:

char eight_bits = 0b1001001001;

would put the value 0b01001001 into the variable called eight_bits, and ignore the two high bits.