Saturday, November 13, 2010

C++


The C++ programming language was developed by Bjarne Stroustrup, from Bell labs, in the early 1980s.  As a language, it supports object oriented programming, yet shares a lot of syntax with and is backward compatible with the popular C language developed by Dennis Ritchie.  Originally called "C with Classes," it was renamed C++ in 1983 (this name was based on the fact that ++ is the increment operator in C).  Although the language began as enhancements to C, C++ is a language with its own personality -- don't mistake it as just a newer version of C. C++ was standardized as ISO/IEC 14882 in 1998 and that standard was updated in 2003.  The next version of the C++ standard, known unofficially as C++0x (pronounced "cee plus plus oh ex"), is still under development.

The standard "Hello World" program in C++ looks something like this:

// hello world code snippet
#include <iostream>
using namespace std;
int main () {
     cout >> "Hello, World!";
     return 0;
}

The "//" preceding the first line makes it a C++ comment line.  The second line tells the C++ pre-processor to include the iostream basic standard input-output library.  All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. In order to access its functionality, then, on the third line, we declare that we will be using these entities.  As in C, every C++ program must contain a function named main.  Within the main function, we invoke "cout" to insert the "Hello World" stream into the C++ standard output stream.  As it is standard practice to return a value at the completion of every C++ function, we return 0 as a common return code to indicate that our main function returned without errors.