O'Reilly logo

Head First C by Dawn Griffiths, David Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 2; else return ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required