Introduction to C++

I chose C++ for this tutorial because it is an advanced, powerful language, yet
it is relatively easy to introduce and learn. Another reason I chose it is
because most modern, high-performance computer programs are written using C++.
Yet another reason is because C++ is not owned by a corporation. Java (a very
advanced language, one receiving much well-deserved attention) is owned by Sun
Microsystems, who has sole control over it, and who expects to make a profit
from it eventually. Visual Basic is owned by Microsoft, resulting in many of
the same limitations. C++ is owned by no one, therefore it is owned by everyone.

By the way, don't get confused — Microsoft's product Visual C++ is not
C++. They are different things. One is a computer language, the other is a
consumer product that embodies a version of C++ geared to a particular
operating system — Windows.

This tutorial teaches C++. If you learn C++, you can also learn Visual C++. The
reverse is not necessarily true.

Each major platform has a C++ compiler, some have several. If you run Windows,
you can acquire a C++ compiler for free. For Linux and other versions of Unix,
a C++ compiler is most likely already installed.

C++ knows about objects (an advanced topic that will be touched upon in this
tutorial) and therefore can teach sound programming techniques from the very
beginning.

C++ is a compiled computer language. This means the original source code is
translated into a specific machine's native tongue, all at once, before the
program is run. The program the computer runs is composed entirely of
instructions known to it, requiring no further interpretation.

A compiler is a very specialized computer program that translates source code
into
machine-specific code. Compiler writing is very difficult and esoteric, and is
one of the more advanced and complex parts of computer science.

It is not too much to say that a compiler writer is to a computer programmer as
a computer programmer is to someone who thinks they speak Latin in Latin
America.

The other major approach to running a computer program is called
interpretation. An interpreter converts a
computer program into the host machine's native tongue, instruction by
instruction, as the program runs. This is a nice environment in which to write
programs, but if the program is simply used and is no longer being developed,
much time is wasted re-interpreting instructions that could be translated just
once and stored in translated form.

Because a compiler translates the entire program at once, compiled programs are
faster than interpreted programs, and are preferred for tasks that require high
performance.

There are two principal reasons for high-level languages like C++. The first is
to make program development easier — each instruction written in C++ might
represent dozens or hundreds of lower-level native instructions. The second is
to make programs portable — if sufficient care is taken in development, a
program written for one computer can be re-compiled and run on another.
Therefore, a programmer need only learn one computer language, instead of one
language per computer architecture. If a single program can be run on any
machine, the unit price of software can go down.

It would be nice if there were an interpreted version of C++, for program
development work only, so the developer would not have to re-compile after each
trivial change. But this hasn't happened yet, and in any case it would probably
be an expensive environment. One of my goals in this project is to cost the
student nothing.

Because of my wish for quick feedback to the student, in this tutorial you will
find pages with programs that appear to run instantly, at each keystroke. These
are actually JavaScript programs, not C++ programs. I use them whenever the
immediate response of JavaScript is desirable, and when the similarity between
JavaScript and C++ allows one to reasonably imitate the other.

Each of the JavaScript demonstration program that imitates a feature of C++ can
be created in C++ as well, and many of the JavaScript demonstration programs
are accompanied by equivalent C++ source listings, so you can compile and test
in C++, to discover for yourself what the differences are.

Finally, to answer what is certainly the question most often asked by students
— Shouldn't I learn C before C++? The answer — no, not
unless you think you need to know how to ride a horse before learning how to
ride a motorcycle. Or unless you think you should learn German, French and
Latin before learning English (thus learning some of the pieces from which
English is
constructed). The second is actually a great idea, if you have the time. But no
one seems to. It's the same with programming.

This tutorial presumes some familiarity with computers and programming. If you
have never written a computer program in any language before, if you think
computers can get along fine without the added complexity of programs, this
tutorial may not be for you.