about summary refs log tree commit diff stats
path: root/org/c/ex_05.org
blob: 799712f2533ece8f41b0c22dbb998cfbee3a1f03 (plain) (blame)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
* Exercise 5
** Operators
*** arithmetic operators
| operator | description |
|----------+-------------|
| +        | add         |
| -        | subtract    |
| *        | multiply    |
| /        | divide      |
| %        | modulus     |
| ++       | increment   |
| --       | decrement   |

*** relational operators
| operator | description        |
|----------+--------------------|
| ==       | equal              |
| !=       | not equal          |
| >        | greater than       |
| <        | less than          |
| >=       | greater than equal |
| <=       | less than equal    |

*** logical operators
Logical operators perform logic tests. They weirdest one is the [[https:www.freecodecamp.org/news/c-ternary-operator/][ternary operator]].

The ternary operator is sort of like a different way to write an if/else statement.

#+BEGIN_SRC plaintext
condition ? value_if_true : value_if_false
#+END_SRC

| operator | description     |
|----------+-----------------|
| &&       | logical and     |
| ||       | logical or      |
| !        | logical not     |
| ? :      | logical ternary |

*** bitwise operators
Bitwise operators are the weirdos, and the ones you don't often encounter in other languages...or like, in JavaScript, I guess. They alter bits directly. They are useful when working in low-level systems.

| operator | description              |
|----------+--------------------------|
| &        | bitwise and              |
| |        | bitwise or               |
| ^        | bitwise xor              |
| ~        | bitwise one's complement |
| <<       | bitwise shift left       |
| >>       | bitwise shift right      |

*** assignment operators
Assignment operators assign expressions to variables.

| operator | description              |
|----------+--------------------------|
| =        | assign equal             |
| +=       | assign plus-equal        |
| -=       | assign minus-equal       |
| *=       | assign multiply-equal    |
| /=       | assign divide-equal      |
| %=       | assign modulus-equal     |
| <<=      | assign shift-left-equal  |
| >>=      | assign shift-right-equal |
| &=       | assign and-equal         |
| ^=       | assign xor-equal         |
| |        | assign or-equal          |

*** data operators
These deal with aspects of pointers, member access and various other data structures in C.

| operator | description           |
|----------+-----------------------|
| sizeof() | get the size of       |
| []       | array subscript       |
| &        | the address of        |
| *        | the value of          |
| ->       | structure dereference |
| .        | structure reference   |