TOC PREV NEXT INDEX

C++: A Dialog


APPENDIX A Tying up Loose Ends


Now that you've reached the end of this book, some questions have probably occurred to you. For example:
1. Am I a programmer now?
2. What am I qualified to do?
3. Where do I go from here?
4. Is that all there is to C++?
Before we get to the answers to these questions, let's take care of some assorted topics that are likely to be covered in any other book that you might read on programming in C++, so that they aren't foreign to you when you encounter them in the future.

Operator Precedence

You may recall from high school arithmetic that an expression like 5 + 3 * 9, is calculated as though it were written 5 + (3 * 9), not (5 + 3) * 9; that is, you have to perform the * before the +, so that the correct result is 32, not 72, as it would be under the latter interpretation. The reason for performing the operations in the former order is that multiplication has a higher precedence than addition, which is just another way of saying that multiplication is performed before addition in the same expression. Well, every operator in C++ also has a precedence that determines the order of application of each operator in an expression with more than one operator. This seems like a good idea at first glance, since after all, arithmetic does follow precedence rules like the one we just saw. Unfortunately, C++ is just a little more complicated than arithmetic, and so its precedence rules are not as simple and easy to remember as those of arithmetic. In fact, there are 17 different levels of precedence, which no one can remember. Therefore, everyone (or at least, everyone who is sensible) ends up using parentheses to specify what order was meant when the expression was written; of course, if we're going to have to use parentheses, then why do we need precedence rules in the first place?

Another Native Data Type

We've used almost all the native data types, but there is one other native type that you might see in other programs and in other textbooks, so I should tell you about it now. This other native type is float, which, like the double type we've already seen, is used to store values that can contain fractional parts, (so-called floating-point numbers). Why are there two of these types rather than only one? The main difference between float and double is that the implementation of float in most compilers takes less memory than the implementation of double; typically floats are 4 bytes long and doubles are 8 bytes long. As a result, a double can store larger values and maintain higher accuracy. However, the greater memory consumption of doubles, which may not be important when we're dealing with a few values, can be quite important if we have a Vec or array of thousands or millions of elements and don't need very high accuracy; in that case, we may want to use floats instead of doubles.1

Wrapping Up

The answer to the first three questions at the beginning of this chapter, as usual with such open-ended topics, is "It all depends". Of course, I can give you some general answers. Let's start with questions 1 and 2.
If you have done all of the exercises in this book, you certainly have earned the right to call yourself a programmer - you've read quite a bit of code and have written some nontrivial programs. But, of course, this doesn't mean that you're a professional programmer. No book can turn a novice into a professional - in any field. That takes a lot of hard work, and although you've undoubtedly worked hard in understanding this book and applying your understanding to the exercises, you still have a lot to learn about programming.
Questions 3 and 4 are also closely related. You now have enough background that you should be able to get some benefit from a well-written book about C++ that assumes you are already acquainted with programming. That would be a good way to continue and the bibliography has some suggestions as to what books you might read next. As for whether we've covered everything about C++, the answer is unequivocal: absolutely not. I would estimate that you are now familiar with perhaps 10% of the very large, complicated, and powerful C++ language; however, that 10% is a good foundation for the rest of your learning in this subject. Most books try to cover every aspect of the language and as a result, cannot provide deep coverage of fundamentals. I've worked very hard to ensure that you have the correct tools to continue your learning. Good luck!
1
The C++ standard requires only that a double be at least as long as a float, but in most implementations a double is twice the size of a float.


www.steveheller.com
steve@steveheller.com
TOC PREV NEXT INDEX