summaryrefslogtreecommitdiff
path: root/reference/C/CONCEPT/expressions.html
blob: a3dac056c0ba459d5fbb19c51912d9a8913456c1 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<head>
<title>C operators</title>
</head>
<body bgcolor="#ffffcc">
<hr>
<center>
<h1>C Operators/Expressions</h1>
</center>
<hr>
<p>

Operators are used with 
<a href="../glossary.html#operand">operands</a>
to build expressions. For example the 
following is an expression containing two operands and one oprator.

<pre>
        4 + 5
</pre>

The following list of operators is probably not complete but does highlight 
the common
operators and a few of the outrageous ones....
<p>
C contains the following operator groups.
<ul>
<li><a href="#arith">Arithmetic</a>
<li><a href="#ass">Assignment</a>
<li><a href="#rel">Logical/relational</a>
<li><a href="#bit">Bitwise</a>
<li><a href="#star">Odds and ends!</a>
<p>
<li><a href="precedence.html">Operator precedence table.</a>
</ul>
The order (precedence) that operators are evaluated can be seen 
<a href="precedence.html">here.</a>

<h2><a name=arith>Arithmetic</h2>
<pre>
        +
        -
        /
        *
        %       <a href="../EXAMPLES/modulo.c">modulo</a>
        --      <a href="inc_dec.html">Decrement</a> (post and pre)
        ++      <a href="inc_dec.html">Increment</a> (post and pre)
</pre>
<h2><a name=ass>Assignment</h2>
These all perform an arithmetic operation on the lvalue and assign the 
result to the lvalue. So what does this mean in English? Here is an example:
<pre>   counter = counter + 1; </pre>
can be reduced to 
<pre>   counter += 1;           </pre>
Here is the full set.
<pre>
        =
        *=      <a href="assignment.html">Multiply</a>
        /=      <a href="assignment.html">Divide.</a>
        %=      <a href="assignment.html">Modulus.</a>
        +=      <a href="assignment.html">add.</a>
        -=      <a href="assignment.html">Subtract.</a>
        <<=     <a href="assignment.html">left shift.</a>
        >>=     <a href="assignment.html">Right shift.</a>
        &=      <a href="assignment.html">Bitwise AND.</a>
        ^=      <a href="assignment.html">bitwise exclusive OR (XOR).</a>
        |=      <a href="assignment.html">bitwise inclusive OR.</a>
</pre>
<h2><a name=rel>Logical/Relational</h2>
<pre>
        ==      Equal to
        !=      Not equal to
        >
        <
        >=
        <=
        &&      <a href="../SYNTAX/logical.html">Logical AND</a>
        ||      <a href="../SYNTAX/logical.html">Logical OR</a>
        !       <a href="../SYNTAX/logical.html">Logical NOT</a>
</pre>
<h2><a name=bit>Bitwise</h2>
<pre>
        &       <a href="../CONCEPT/bitwise.html">AND (Binary operator)</a>
        |       <a href="../CONCEPT/bitwise.html">inclusive OR</a>
        ^       <a href="../CONCEPT/bitwise.html">exclusive OR</a>
        <<      <a href="../CONCEPT/bit_shift.html">shift left</a>. <font color=brown>C ++ use of <a href=../../CPLUSPLUS/SYNTAX/ops.html>&lt;&lt;</a></font>

        >>      <a href="../CONCEPT/bit_shift.html">shift right</a>. <font color=brown>C ++ use of <a href=../../CPLUSPLUS/SYNTAX/ops.html>&gt;&gt;</a></font>
        ~       <a href="../CONCEPT/bitwise.html">one's complement</a>
</pre>
<a name=comma>
<h2><a name=star>Odds and ends!</h2>
<pre>
        sizeof() <a href="../SYNTAX/sizeof.html">size</a> of objects and <a href="data_types.html">data types</a>.
                 <a href="../FUNCTIONS/strlen.html">strlen</a> may also be of interest.
        &       <a href="../EXAMPLES/address.c">Address of</a> (Unary operator)
        *       <a href="../EXAMPLES/address.c">pointer</a> (Unary operator)
        ?       <a href="../SYNTAX/conditional.html">Conditional expressions</a>
        :       <a href="../SYNTAX/conditional.html">Conditional expressions</a>
        ,       <a href="../SYNTAX/comma.html">Series operator.</a>
</pre>
<hr>
<p>
<h2>C++ Extensions</h2>

<font color=brown>
Read about :: &gt;&gt; and &lt;&lt; in the world of C++
<a href=../../CPLUSPLUS/SYNTAX/ops.html>here!</a>
</font>
<hr>
<p>
<center>
<table border=2 width=80% bgcolor=ivory>
<tr align=center>
<td width=25%>
<a href="../cref.html">Top</a>
</td><td width=25%>
<a href="../master_index.html">Master Index</a>
</td><td width=25%>
<a href="../SYNTAX/keywords.html">Keywords</a>
</td><td width=25%>
<a href="../FUNCTIONS/funcref.htm">Functions</a>
</td>
</tr>
</table>
</center>
<p>
 
<hr>
<address>Martin Leslie
<script language="JavaScript">
<!--  //
document.write(document.lastModified);
// -->
</script>
</address>