Lesson 2B Basic Operator in C
Lesson 2B Basic Operator in C
C++
GEADLITE – LIVING IN THE INFORMATION
TECHNOLOGY ERA
Operator
Once we know of the existence of variables and constants, we
can begin to operate with them. For that purpose, C++ integrates
operators. Unlike other languages whose operators are mainly
keywords, operators in C++ are mostly made of signs that are not
part of the alphabet but are available in all keyboards. This makes
C++ code shorter and more international, since it relies less on
English words, but requires a little of learning effort in the
beginning.
You do not have to memorize all the content of this page. Most
details are only provided to serve as a later reference in case you
need it.
Assignment (=)
The assignment operator assigns a value to a variable.
a = 5;
This statement assigns the integer value 5 to the variable a. The part at
the left of the assignment operator (=) is known as the lvalue (left value)
and the right one as the rvalue (right value). The lvalue has to be a
variable whereas the rvalue can be either a constant, a variable, the
result of an operation or any combination of these. The most important
rule when assigning is the right-to-left rule: The assignment operation
always takes place from right to left, and never the other way:
Assignment (=)
a = b;
Comparison Result
5 >= 6 False
1.7 < 1.8 True
4 + 2 == 5 False
2 * 4 != 7 True