liveBook · Manning

Chapter 4: Expressing computations

What you will learn in chapter 4 of Modern C, Third Edition

Introduces C expressions as code that computes values and distinguishes arithmetic expressions from comparisons.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces C expressions as code that computes values and distinguishes arithmetic expressions from comparisons.

Key terms: expressions, arithmetic expressions, comparison operators

4.1 Operands and operators

This section introduces the range of size_t, names operators and operands, and shows how evaluating an object supplies a value for an operation.

Key terms: size_t, SIZE_MAX, unsigned integer types, <stdint.h>, operator, operand, object, value, evaluated, arithmetic operation

4.2 Arithmetic

4.2.1 +, -, and *

This section explains addition, subtraction, multiplication, unary plus and minus, and when arithmetic on size_t gives a representable mathematical result.

Key terms: arithmetic operators, sub-expressions, parentheses, binding, unary variants, negation, unsigned arithmetic, size_t, SIZE_MAX, representable

4.2.2 Division and remainder

Explains how division and remainder work for unsigned values, why their second operand cannot be zero, and how unsigned arithmetic wraps around.

Key terms: division, remainder, /, %, unsigned /, unsigned %, overflow, unsigned arithmetic, wraps around, size_t

4.3 Operators that modify objects

This section explains how assignment, compound assignment, and increment and decrement operators modify objects, and why side effects in expressions should be kept simple.

Key terms: assignment, assignment operators, object, value, increment operator, decrement operator, prefix increment, postfix increment, postfix decrement, side effects

4.4 Boolean context

Introduces Boolean-context operators as condition-dependent expressions that yield 0 or 1 and groups them into comparisons and logical evaluation.

Key terms: comparisons, logical evaluation

4.4.1 Comparison

This section explains what C comparison operators return and shows how their results can be used as numbers, including as array indexes.

Key terms: comparison operators, strict comparisons, false, true, array indexing, sign[false], sign[true]

4.4.2 Logic

This section explains C’s logical operators, their 0-or-1 results, and how short-circuit evaluation can skip an unnecessary operand.

Key terms: !, &&, ||, truth values, !!largeA[i], short-circuit evaluation

4.5 The ternary or conditional operator

This section explains how the conditional operator chooses a value while evaluating only the needed branch, and briefly illustrates conditional compilation.

Key terms: ternary operator, conditional operator, expression, operands, conditional compilation, preprocessor directives, #ifdef, #error, __STDC_NO_COMPLEX__

4.6 Evaluation order

This section explains which C operators guarantee operand evaluation order, why most expressions and function arguments do not, and how to avoid depending on an unspecified order.

Key terms: &&, ||, ?:, evaluation order, comma operator, ,, A[i, j], side effects, function arguments, sequence

4.7 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 3: Everything is about control Chapter 5: Basic values and data →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.