This article will give you a good understanding of the basic concepts and practices of the C++ language, so that you will have the foundation to eventually learn these ideas in detail as you continue working with the language. It is excerpted from Ivor Horton's Beginning ANSI C++ The Complete Language (Apress, 2004; ISBN 1590592271).
AT FIRST SIGHT, a connection between learning C++ programming and poultry would seem to be unlikely, but there isóitís the chicken-and-egg problem. Particularly in the early stages of understanding C++, youíll often have to make use of things in examples before you properly understand them. This chapter is intended to solve the chicken-and-egg problem by giving you an overview of the C++ language and how it hangs together, and by introducing a few of the working concepts for things that youíll be using before you have a chance to understand them in detail.
All the concepts that youíll read about here are covered in more detail in later chapters. Most of this information is just to set the scene before you get into the specifics of writing C++ programs. Youíll see what a simple C++ program looks like, and then youíll pull it to pieces to get a rough idea of what the various bits do. Youíll also look at the broad concepts of programming in C++ and how you create an executable program from the source code files youíll be writing.
Donít try to memorize all the information in this chapter. Concentrate on getting a feel for the ideas presented here. Everything mentioned in this chapter will come up again in later chapters. Hereís an overview of what this chapter covers:
What the features of C++ are that make it so popular
What the elements of a basic C++ program are
How to document your program source code
How your source code becomes an executable program
How object-oriented programming differs from procedural programming
Youíre probably familiar with the basic ideas of programming and programming languages, but to make sure weíre on common ground, letís do a quick survey of some of the terms youíll encounter as you progress through the book. You can also put C++ into perspective in relation to some of the other programming languages youíll have heard of.
There are lots of programming languages, each with its advantages and disadvantages, and its protagonists and detractors. Along with C++, other languages that youíre likely to have come across include Java, BASIC (an acronym for Beginnerís All-purpose Symbolic Instruction Code), COBOL (an acronym for Common Business-Oriented Language), FORTRAN (an acronym for formula translator), Pascal (after Blaise Pascal, a French mathematician), and C (simply because it was a successor to a language called B). All of these are referred to collectively as high-level languages, because theyíre designed to make it easy for you to express what the computer is to do, and they arenít tied to a particular computer. Each source statement in a high-level language will typically map to several native machine instructions. A low-level language is one that is close to the native machine instructions and is usually referred to as an assembler language. A given assembler language will be specific to a particular hardware design, and typically one assembler instruction will map to one native machine instruction.
A Potted History
FORTRAN was the first high-level language to be developed, and the first FORTRAN compiler was written in the late 1950s. Even though FORTRAN has been around for over 40 years, itís still used today for scientific and engineering calculations although C++ and other languages have eroded much of its usage.
COBOL is a language exclusively for business data processing applications, and itís almost as old as FORTRAN. Although relatively little new code is written in COBOL, there is an immense amount of code that was written years ago thatís still in use and still has to be maintained. Again, C++ has become the language of choice for many business data processing programs.
BASIC emerged in the 1970s when the idea of a personal computer was being conceived. Interestingly, the first product sold by Microsoft was a BASIC interpreter. The ease of use inherent in the language resulted in a rapid growth in its popularity that continues to this day.
Java was developed in the 1990s. Its original incarnation as a language called Oak was really intended for programming small consumer electronics devices. In 1995 Oak evolved into the Java language for embedding code in web pages and from there into what it is today. The primary reason for the success of Java is its portability. A Java program can run unchanged on any hardware platform that supports it. The syntax of the Java language has many characteristics that make it look similar to C++, but there are significant differences. Although Java gains over C++ on portability, it canít match C++ in execution performance.
C was developed in the early 1970s as a high-level language that could be used for low-level programming, such as implementing operating systems. Most of the Unix operating system is written in C.
C++ was developed by Bjarne Stroustrup in the early 1980s as an object-oriented language based on C. Hence the name, C++, which in C++ means C incremented. Because C++ is based on C, the two languages share a common subset of syntax and functionality, and all of the capabilities in C for low-level programming are retained in C++. However, C++ is a much richer and more versatile language than its ancestor. The vastly improved memory management features and the object-oriented capabilities of C++ means that C functionality represents a very small subset of C++. C++ is still unrivaled in scope, performance, and power. For this reason, the majority of high-performance applications and systems are still written in C++ today.
This article is excerpted from Beginning ANSI C++ The Complete Language by Ivor Horton (Apress, 2004; ISBN 1590592271). Check it out at your favorite bookstore today. Buy this book now.