UNDERSTANDING VARIABLES
Variables are rather quite simple. If you are familiar with variables in math, say x = 1, then understanding programming variables should be very easy. Variables are used to store data such as numbers, letters, words, objects, etc in a format easy for the computer to process.
THE INTEGER:
The integer is the most used data type. It can store any real, whole number between -2,147,483,647 and 2,147,483,647. So numbers such as 12, 55, 40,045, and 2,000,000 are able to be stored in an integer.
Construction of an int variable:
- An integer can be defined by the prefix
int
followed by a name to reference it:int number
, then set your int equal to it's value with an equals sign.int number = 12
. Now end your line with a simicolin(;).int number = 12;
- An integer can be defined by the prefix
Changing the value:
- An intager can always be changed (In 90% of situations). An int can be changed by setting it equal to it's new value by referencing the name you gave it.
number = 15;
- An intager can always be changed (In 90% of situations). An int can be changed by setting it equal to it's new value by referencing the name you gave it.
Adding values:
- Math can be applied to an int using your common math expressions, with the exception of multiply which is notated by an asterix ( * ) rather than an x.