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.

Friday, October 15, 2010

K&R: Where It All Began (C)


While small test programs existed since the development of programmable computers, the tradition of using the phrase "Hello world!" as a test message was influenced by an example program in the well-known book The C Programming Language, written by Brian Kernighan and Dennis Ritchie, and often referred to as simply K&R. The example program from that book prints "hello, world" (without capital letters or exclamation mark), and was inherited from a 1974 Bell Laboratories internal memorandum by Brian Kernighan, Programming in C: A Tutorial, which contains the first known version:

main( ) {
printf("hello, world");
}



The first known instance of the usage of the words "hello" and "world" together in computer literature occurred earlier, in Kernighan's 1972 Tutorial Introduction to the Language B, with the following code:

main( ) {
extrn a, b, c;
putchar(a); putchar(b); putchar(c); putchar('!*n');
}
a 'hell';
b 'o, w';
c 'orld';