4 Expressing computations
This chapter covers
- Performing arithmetic
- Modifying objects
- Working with Booleans
- The ternary operator
- Setting the evaluation order
We’ve already used some simple examples of expressionsC. These are code snippets that compute a value based on other values. The simplest such expressions are arithmetic expressions, which are similar to those we learned in school. But there are others, notably, comparison operators such as ==
and !=
, which we saw earlier.
4.1 Operands and operators
Here, the values and objects on which we will do these computations will be mostly of the type size_t
, which we have already met. Such values correspond to “sizes,” so they are numbers that cannot be negative. Their range of possible values starts at 0
. What we would like to represent are all the non-negative integers, often denoted as \(\mathbb{N}\), \(\mathbb{N}_0\), or “natural” numbers in mathematics. Unfortunately, computers are finite, so we can’t directly represent all the natural numbers, but we can do a reasonable approximation. There is a big upper limit SIZE_MAX
that is the upper bound of what we can represent in a size_t
.
The value of SIZE_MAX
is quite large. Depending on the platform, it is one of
\[\begin{align} 2^{16}-1 &=& 65{,}535\\ 2^{32}-1 &=& 4{,}294{,}967{,}295\\ 2^{64}-1 &=& 18{,}446{,}744{,}073{,}709{,}551{,}615 \end{align}\]