The name C++ comes from a nerdy computer thing. So, for all you non-nerdy people out there, I guess I’d better explain a bit first.
Deep down inside, computers are dumb machines. They can only do the simplest of mathematical operations, which basically means addition and Boolean logic. They can’t even multiply. (Or subtract, for that matter, but there’s a way to get around that using addition.) So, in order to get a computer to do anything even remotely complicated, you have to give it a whole long sequence of instructions to perform. But thinking at the computer’s level is overwhelmingly tedious, not to mention error-prone, since it has to do everything in such tiny, simplistic steps. So people invented programming languages to, in programming terms, “abstract” the computer’s lowest operations. This means that programming languages provide an interface for programmers to use to interact with the computer’s hardware, while leaving what the hardware actually does hidden. The code written by a programmer is translated into machine instructions by another program called a compiler that reads the code and generates the corresponding instructions.
Since programming languages are made to be a medium between how the programmer thinks and how the computer thinks, many programming languages try to make their syntax fairly close to normal writing conventions. So the vast majority of programming languages have these things called operators. Operators are signs that represent ways of combining or changing things, like adding or subtracting numbers. They allow programmers to represent the math that they need the computer to do in the same way they write math normally. So 1+1 in a programming language means the same thing as 1+1 in Human Land, all thanks to the good ol’ + operator, which instructs the computer to add the numbers on either side of it. (One notable exception is Lisp, which sacrifices familiarity in favor of pure awesomeness and therefore dispenses with operators and all the syntactic complication they create. In Lisp, 1+1 is written (+ 1 1). Here, + is not an operator; operators generally constitute their own syntactic category in programming languages, but + in Lisp is an instance of a data type called a symbol. Yes, you read that right. The + is data, too. The fact that the program itself is data in Lisp is a big part of what makes it awesome. But that’s a topic for another time.) Now, a computer never remembers anything unless you explicitly tell it to. You know, because it’s stupid. And when you tell the computer to keep track of a given datum, it stores that datum in a variable. Of course, oftentimes the data you tell a computer to keep track of changes over time (hence the name “variable”), so there are operators to change the values of variables. The most basic one is the assignment operator, which generally looks like = or sometimes :=. Note that this is not the same as the mathematical =. In math, = makes a factual statement that two quantities are the same. In programming, =, when used as an assignment operator, instructs the computer to change the contents of the variable on the left hand side to the value on the right hand side. So, in C, int x=1; means “Let x be a variable that holds integers, and let it be assigned the value 1.” The semicolon is there because every instruction in C (and in all the languages derived from it) has to end with a semicolon. And before you ask, yes, it is, in fact, a pain when you forget to put a semicolon. I still remember the first time I made that mistake. It took forever to figure it out. But I digress.
The name C++ comes from an operator in C. ++ in C is the incrementation operator; it assigns the value of 1 + a variable to that variable. So, if x = 1, then x++; changes x to 2. The name C++ is supposed to imply that C++ is C + 1.
Now, every operator, as far as I know, has a return value. Return values work just like simplifications in math: an operator generates a value, which can then replace the original expression involving the operator. So, 1+1, for example, returns 2; that means that whenever you (or a computer compiling a program, as the case may be) have to evaluate 1+1, you replace the expression 1+1 with 2. Thus, if you write int x=1+1; then the 1+1 is processed, returning 2, and the expression becomes int x=2; . Now, the ++ operator, like every other operator, returns a value, but the way it does so is somewhat unusual. The ++ operator returns a different value depending on whether you write it before or after the variable you want to change. ++x returns the new value of x after incrementation, while x++ returns the old value of x before incrementation. Either way, x is incremented, so if x = 1, then either x++ or ++x will make x become 2. The difference becomes visible when you use an incrementation within another expression. For example, again pretending x = 1, if we write int y = ++x; in a program, x will become 2, 2 will be returned, and the expression becomes int y=2; thus assigning the value 2 to y. So both x and y end up becoming 2. But if we write int y = x++; then x will become 2, but x++ will return x’s old value, 1, and the expression becomes int y=1;. So x becomes 2, while y becomes 1. Both versions update the variable contents to 1 more than its original value, but the expression as a whole returns either the original value or the new value depending on the position of the operator.
So now we know enough to see the irony in the name C++. C++ has the incrementation operator written after the variable C. So C is incremented, and meanwhile, the expression C++ as a whole is equal to C’s old value. So C has advanced a step, but the whole expression C++ is worth what C was before it advanced. Which means that, since C is now one more than it was before, the expression C++ is actually worth 1 less than C.
That’s why, if I ever made yet another C-based language, and if I had to use the incrementation operator in its name, I would call it ++C. But even that doesn’t really make sense, because it implies that I’m changing C, when I’m not really doing anything to C, I’m actually making up another language entirely. Really, the most sensible name would be, well, C + 1. The moral of this story: Don’t try to be clever.
You know what, I wish there weren’t so many clone languages of C. A bunch of languages that are all alike is always depressing, whether in programming or in speech. Anyways, plain old C is good enough for me. And also Lisp, of course. Recursion and lexical closures are always fun.
Now, if you’ll excuse me, I’m going to go make up a language called (+ 1 lisp).