Conditional operator is a bit harder to explain. It takes an expression which produces a Boolean result in order to determine which of two other expressions will be calculated and have its value returned as a result. Its sign is ?:… Read more
Archive for January, 2017
Conditional (ternary) operator
Friday, January 6th, 2017Assignment operators
Friday, January 6th, 2017This is the simplest operator of them all. It’s expressed simply by the equal (=) sign. Assignment operators are used to assign (give) a value to a variable.
They can also be used in cascade. Lets have a look at simple and cascaded assignment:
1 2 3 |
string name = "John Doe"; int x, y, z; x = y = z = 3; |
One very important thing to always remember is NOT to confuse the assignment operator = with the comparison operator == (a very common programming mistake).… Read more
Comparison operators
Friday, January 6th, 2017Another kind of operators we have enumerated are the comparison operators. As their name suggest, comparison operators are used to compare operands. There are 6 comparison operators:
Bitwise operators
Friday, January 6th, 2017Any programmer knows that computers can only process information represented by a series of binary numbers (1 and 0). This means that when we store the number 55 in memory of the computer, it actually stores a series of bits represented as 00110111.… Read more
Concatenator operator
Friday, January 6th, 2017Though we already used the concatenator operator quite a few times, we did not explain it yet. The concatenator operator (+) is used to join values of type string together.
As a side note, it is not necessary for both operands to be of type string.… Read more
Logical operators
Friday, January 6th, 2017Logical operators are quite simple, since they can only produce two outputs: true or false. The basic logical (Boolean) operators are AND (&&), OR (||), XOR (also called “Exclusive OR”, ^) and NOT (or negation, !).
I will show you a sample of the four logical operations and the results that they produce:
Decrementing operator
Friday, January 6th, 2017Decrementing operator is the complementary part of the incrementing operator. What applies to the incrementing operator, also applies for the decrementing one.
Obviously, the difference is in the syntax and behavior. Decrementing operator can be expressed in four ways, just like incrementing one:
1 |
--variable, variable--, variable -= 1, variable =- 1 |
The difference in behavior should be obvious and self-explanatory: instead of adding, we subtract.… Read more
Incrementing operator
Thursday, January 5th, 2017One of the most used operations in programming is incrementing a variable’s value. Incrementing operator is composed of two plus signs: ++ (and has two forms), or a variation of the following two operators: += and =+.
Lets consider the following example:
1 |
variable = variable + 1; |
In the above example, we are assigning a variable the result of adding 1 to its own value.… Read more
Arithmetical operators
Thursday, January 5th, 2017Basically, arithmetical operators (+, -, *, /) are the same as the mathematical ones. However, there are a few things to point out.
The most important thing to watch out is the kind of result you are expecting. If you will use two integers to perform a division, do not expect to get a real number, do not expect to get rounding, or any fractional part.… Read more
Operator precedence
Thursday, January 5th, 2017If you still remember from math class (yeah, right! 😀 ), some operators have precedence over others, meaning that multiplication is more important than addition and will be calculated first. Operator precedence should always be remembered when dealing with more than two operands.… Read more