Another Way to Create Variables
Continuing from last video... I would like to show you an alternative to create a variable. We can actually declare and allocate the space for a variable without giving it a value. To do this we simply omit assigning it a value. However, we need to ensure that we give our variable a value later in the program before we reference it.
There are a series of arithmetic operators that we can apply to variables and data within out programs. Some operations (such as multiplication and division) are only defined for numbers (ints and doubles). However, we can actually use the + operator on Strings to concatenate them. The list of common arithmetic operators is seen below.
An example of these operators in use can be seen below.
Operations With Doubles
Whenever performing these operation with doubles we must ensure we are storing the value to our expression in a float typed variable. Whenever even one double is present in a mathematical expression the result is always a double.
Order of Operations
These operators can be used in conjunction with one another, this means they need some order of precedence. They follow the standard order of operations
M multiplication & modulus
Operations on Strings
The + operator is supported on String data types. When we add two strings that is now as concatenation. The string that is being added will be appended to the other string.