Chapter 4. Expressing computations
This chapter covers
- Performing arithmetic
- Modifying objects
- Working with booleans
- Conditional compilation with the ternary operator
- Setting the evaluation order
We’ve already made use of 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.
In this chapter, 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 N, N0, 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.
Takeaway 4.1
The type size_t represents values in the range [0, SIZE_MAX].
The value of SIZE_MAX is quite large. Depending on the platform, it is one of
- 216 – 1 = 65535
- 232 – 1 = 4294967295
- 264 – 1 = 18446744073709551615