เครื่องหมาย¶
กำหนดค่า¶
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 int x = 1;
7 int y = 2, z = 3;
8
9 x = 9;
10 y = 2 + x;
11 z = 2 + (x = 9);
12 z = y = x = 10;
13 return 0;
14}
เรขาคณิต¶
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 int x = 3, y = 4, z;
7
8 z = x + y;
9 z = x - y;
10 z = x * y;
11 z = x / y;
12 z = x % y;
13
14 return 0;
15}
ผสม¶
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 int x = 3, y = 4;
7
8 y += x; // y = y + x;
9 y -= x;
10 y *= x;
11 y /= x;
12 y %= x;
13
14 y >>= x; // y = y >> x;
15 y <<= x;
16 y &= x;
17 y |= x;
18
19 return 0;
20}
เพิ่มค่า¶
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 int x = 3, y = 4;
7
8 x++; // x = x+1;
9 x--; // x = x-1;
10
11 cout << u8"ค่า x :" << x << endl;
12 cout << u8"ค่า x++ :" << x++ << endl;
13 cout << u8"ค่า x-- :" << x-- << endl;
14 cout << u8"ค่า x :" << x << endl;
15 cout << endl;
16 cout << u8"ค่า y :" << y << endl;
17 cout << u8"ค่า ++y :" << ++y << endl;
18 cout << u8"ค่า --y :" << ++y << endl;
19 cout << u8"ค่า y :" << y << endl;
20
21 return 0;
22}
เปรียบเทียบ¶
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 int x = 3, y = 4;
7 bool z, b = true;
8
9 z = (x == y);
10
11 cout << "b = " << b << endl;
12 cout << "z = " << z << endl;
13 cout << (x == y) << endl;
14 cout << (x != y) << endl;
15 cout << (x > y) << endl;
16 cout << (x < y) << endl;
17 cout << (x >= y) << endl;
18 cout << (x <= y) << endl;
19
20 return 0;
21}
ทางตรรกศาสตร์¶
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 int x = 3, y = 4, z = 6;
7 bool a, b = false;
8
9 a = (x <= y);
10
11 cout << "!true = " << !true << endl;
12 cout << "!false = " << !false << endl;
13 cout << "!a = " << !a << endl;
14 cout << !(x == y) << endl;
15 cout << ( (x <= y) && ( y <= z) ) << endl;
16 cout << ( (x <= y) || ( y <= z) ) << endl;
17
18 return 0;
19}
กำหนดค่าตามเงื่อนไข¶
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 int x = 3, y = 4, z;
7 bool a, b = false;
8
9 z = (x > y)? x : y;
10 cout << z << endl;
11
12 z = (b)? x : y;
13 cout << z << endl;
14
15 return 0;
16}
คอมมา ,¶
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 int x = 3, y = 4, z;
7
8 z = (x*3, y*2);
9 cout << z << endl;
10
11
12 return 0;
13}
ปรับบิต¶
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 int x = 3, y = 4, z;
7
8 z = (x & y);
9
10 cout << (x & y) << endl;
11 cout << (x | y) << endl;
12 cout << (x ^ y) << endl;
13 cout << ~x << endl;
14 cout << (x << 2) << endl;
15 cout << (x >> 4) << endl;
16
17 return 0;
18}
เปลี่ยนชนิดข้อมูล¶
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 int x = 3;
7 float y = 4.0f;
8 double z = 4.0L;
9
10 x = (int) y;
11 x = int (y);
12 y = float (z*x);
13
14 return 0;
15}
sizeof¶
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 char c = 'A';
7 int x = 3;
8 long long xl = 3;
9 float y = 4.0f;
10 double z = 4.0L;
11
12 cout << sizeof(char) << endl;
13 cout << sizeof(c) << endl;
14 cout << sizeof(x) << endl;
15 cout << sizeof(xl) << endl;
16 cout << sizeof(y) << endl;
17 cout << sizeof(z) << endl;
18
19 return 0;
20}
ลำดับความสำคัญของ¶
Level |
Operators |
Process Sequence / Description |
---|---|---|
1 |
:: |
Left-Right |
2 |
++ -- |
|
() |
Left-Right |
|
[] |
||
. -> |
||
++ -- |
||
3 |
~ ! |
|
+ - |
||
& * |
Right-Left |
|
new delete |
||
sizeof |
||
(type) |
||
4 |
.* ->* |
|
5 |
* / % |
|
6 |
+ - |
|
7 |
<< >> |
|
8 |
< > <= >= |
|
9 |
== != |
|
10 |
& |
|
11 |
^ |
|
12 |
ǀ |
bitwise OR |
13 |
&& |
|
14 |
ǁ |
relation OR |
15 |
= -= *= |
assignment |
16 |
, |