forked from cirosantilli/cpp-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperators.cpp
More file actions
37 lines (30 loc) · 711 Bytes
/
operators.cpp
File metadata and controls
37 lines (30 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
# Assign operator
*/
#include "common.hpp"
int main() {
/*
Unlike in C, some C++ operators return lvalues.
- http://www.quora.com/Why-does-the-pre-increment-operator-in-C++-gives-lvalue-instead-of-rvalue-as-in-C
*/
{
// =
{
int i = 0, j = 1, k = 2;
(i = j) = k;
assert(i == 2);
assert(j == 1);
assert(k == 2);
}
// Prefix ++
{
int i = 0;
assert(++++i == 2);
assert(i == 2);
// ERROR: but not postfix.
//i++++;
}
// ERROR: as in C, most other operators do not return lvalues
//(i + j) = k;
}
}