Expressions
- operators -- + , - ! = \&\& , ||
- indexing -- o[ e ]
- application -- o(...)
- access -- o.m(...)
- dereference -- p->m(...)
- in/decrement -- o++, o--
- conditional -- b ? e1 : e2
Assignment
- var = expression +=-=
slide: C++ -- expressions (2)
Value expressions may be created using
arithmetic and comparison operators
(including == for equality and !=
for inequality).
As logical operators, C++ includes
conjunction ( && ) and disjunction ( || ),
as well as a number of bitwise logical operators.
Also, we have an indexing operator
(which may be defined for arbitrary types),
an application operator
(that may also be defined for arbitrary types),
an access operator
(that is as a standard used for member function
invocation or method calls),
a dereference operator
(that is used to invoke member functions through a
pointer to an object)
and in- and decrement
operations
(that, again, may be defined for arbitrary types).
Needless to say, user-defined operators
must be applied with care.
Also, we have a conditional expression of the form
b ? e1 : e2 ,
which evaluates in that order
and delivers as its value.
Assignments in C++, it is important to note,
are written as , with a single
symbol.
This convention is known to cause mistakes by programmers
raised with languages such as Pascal or Modula-2.
In addition, C++ offers modifying assignments,
which may be used as, for example, in n += 1,
which is identical in meaning to n = n + 1.