Appendix A. Leftovers: The top ten things (we didn’t cover)

image with no caption

Even after all that, there’s still a bit more.

There are just a few more things we think you need to know. We wouldn’t feel right about ignoring them, even though they need only a brief mention, and we really wanted to give you a book you’d be able to lift without extensive training at the local gym. So before you put the book down, read through these tidbits.

#1. Operators

We’ve used a few operators in this book, like the basic arithmetic operators +, -, *, and /, but there are many other operators available in C that can make your life easier.

Increments and decrements

An increment and a decrement increase and decrease a number by 1. That’s a very common operation in C code, particularly if you have a loop that increments a counter. The C language gives you four simple expressions that simplify increments and decrements:

image with no caption

Each of these expressions will change the value of i. The position of the ++ and -- say whether or not to return the original value of i or its new value. For example:

image with no caption

The ternary operator

What if you want one value if some condition is true, and a different value if it’s false?

if (x == 1) return ...

Get Head First C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.