Abstract
A quick review of the legendary K&R's 'hello world' program and some of its previous versions.
The First Program to Write: First Edition
Accoding to Brian W. Kernighan and Dennis M. Ritchie in their book ‘The C Programming Language’ published in 1978, the first program to write ‘is the same for all languages: Print the words hello, world’. I want to highlight here the words ‘the same for all languages’. Why K&R agreed on wrote that? From a practical point of view, printing a greeting on the screen it is one of the simplest program to give a glimpse of the syntax and the general feeling and ergonomics of a language. Perhaps it is just a check that everything is working well in the machine: the editor, compiler, linker and so on. Although, I supppose that pure functional languages may prefer a recursive algorithm as its own ‘hello, world’. Their point was just start learning by programming something easy and quickly, and be able to see and verify the correctness of the development environment and the program itself in short time.
The code writen in their book for the hello world program was this:
main()
{
printf("hello, world\n");
}
Is worth noting that a modern compiler should not compile that program because it propably warn about a function ‘printf’ as not defined, and because the main function does not have a return type written before its name. The first program in the context of the C language prints a message on the terminal. Now, the words chosen to print out are worth of some reflection. They are a simple greeting to the world. Who is greeting? Well, the simplest answer is nobody, machines does not greet. However, in the context of the tutorial written by K&R, the greet could come from the novice programer that is following their instruction. It is her/his first program in C, so it is worth to celebrate and to say to the world that here is the humble beginning and a seed of a new great developer.
Kernighan and Ritchie started their book by doing a general description of the C language: ‘C is a general-purpose programming language which features economy of expression, modern control flow and data structures and a rich set of operators’. Then, they wrote a more detailed description of the language stressing its simplicity, portability, low level and not strongly typed nature among other features. Simplicity and expresiveness were ways they used to describe the language, though those are features that cannot be perceived just for the first program ever written in the language. Those are aesthetic values that take time to appretiate and see as one of the most important features of the language. As for today, more than 40 years after the publication of the K&R’s book, still the C language is on the top of the most used programming languages in the research and production context. And, guess what? One of the most appretiated features is its simplicity and expresiveness.
The authors also believed strongly that ‘the only way to learn a new language is to write programs in it’. That was written in the page 4 of the chapter zero of their book, and it perhaps states a pedagogical conviction: learning is something that happens in relation with the thing we are trying to learn. In the case of the K&S’s book, it is all about a good enough immersion in the language to have a good starting point. After that, K&R though that a good mentor will be necessary to a more advanced development of skills and way of thinking that C allows to the developer.
It would be a matter of time that the use of the language itself, its syntax and its semantics, will be the door to a that world of simplicity and expresiveness that K&R vewed to their innovation. If the limits of the language are the limits of the the our world, then the first program to write is not as important as the path to be able to see above the clutter and appretiate the eternal mathematical glipmse behind the inspiration of the C way to expreess computation.
A Previous Hello World
According to Wikipedia, a previous ‘hello, world’ was written by Kernighan at Bell Laboratories in 1974. It was written in a short paper called ‘Programming in C - A Tutorial’. At the end of this seed their a link to the document if you are curious about. In that tutorial, Kernighan wrote that ‘C lets you write programs clearly and simply […] it encourages modularity and good program organization; and it provides good data-structuring facilities.’ A couple of lines after such a good description of the C language, a subtitle appears: ‘A Simple C Program’ and the our famous ‘hello, world’ program appears again. The program is the same as pictured above, but with two small variations in its style and the message: The first brace is in the same line of the name of the function, and the message does not have the new line scape sequence at the end. Here is the 1974 version of ‘hello, world’:
main() {
printf("hello, world");
}
Other Previous Hello Worlds
It turns out that a previous ‘hello, world’ was written in 1972 by Brian W. Kernighan. The text is a tutorial introduction to the B language. In the sixth part of the tutorial called ‘Characters: putchar; Newline’ we can find the following program:
main( ) {
auto a;
a= 'hi!';
putchar(a);
putchar('*n');
}
That program prints ‘hi!’ to the terminal. The intention of such program was to illustrate the use of character constants and variables. The sequence ‘*n’ was the B jargon for new line character. Printing ‘hi!’ is not the same as printing ‘hello, world’ to the terminal, but if I take not the message content by itself, but a greeting message as the first program, then the first ‘hello, world’ program is the ‘hi!’ one. The story, However, does not finish here. Later in the B tutorial, Kernighan wrote other programs to illustrate other B concepts, and in some of them the ‘hello, world’ program appeared. For example: we can find a ‘hello, world’ program to illustrate external variables which exists external to all functions, and are (potentially) available to all functions. The code of such progrsm is this:
main( ) {
extrn a, b, c;
putchar(a); putchar(b); putchar(c); putchar(’!*n’);
}
a ’hell’;
b ’o, w’;
c ’orld’;
After the program to show the concept of extern variables, Kernighan wrote another simple example of a function calling ahother function. The example shows the main function calling twice the put2char() function, and the put2char call twice the putchar one. As a result of such stack of function calls a message is printed to the terminal: ‘hello, world’. Here is the code:
main( ) {
extrn a,b,c,d;
put2char(a,b) ;
put2char(c,d) ;
}
put2char(x,y) {
putchar(x);
putchar(y);
}
a ’hell’; b ’o, w’; c ’orld’; d ’!*n’;
Greeting the World
At the end, in the tradition of Bell Labs programming langugages like B or C, the ‘hello, world’ of all other ‘hello, worlds’ maybe was just a ‘hi!’. But ‘hi!’ has a brother: ‘hello, world’. It turned out that the older brother was not as famous as his little one. Since 1972, lots of ‘hello, worlds’ have existed, including the famous C Language one, and it became an initiatic rite for programmers and developers alike, and for the next generations of programming languages as well.
Perhaps, the ritual is just to greet the world beyond the particular greeting message printed to the terminal. Greting the world means that a new thing has started, a new beginning has come, and perhaps participating of the B, C tradition is another way to wish that everything will be all right.

Hello World Program signed by Brian Kernighan - 1978.
The First Program to Write: Second Edition
In the second edition of ‘The C Programming Language’ published in 1988, the first program to write added the missing line of the first edition. Also, the authors stated that C had changed since the publication of the first edition in 1978. One of those changes happened in 1983, when the American National Standards Institute (ANSI) established a committee whose goal was to produce ‘an unambiguous and machine-independent definition of the language C’ while still retaining its spirit. The result was the ANSI standard for the C language.
The second edition of ‘The C Programming Language’ describes C as defined by the ANSI standard, and the is focused on help the reader on how to programm in C. Although C is a language that is easy to learn, it is not a language that is easy to master. It takes years of experience to undertand its quirks and its quarks. As the authors themselves expressed since 1978:
'C has proven to be a pleasant, expressive, and versatile language for a wide variety of programs. It is easy to learn, and it wears well as one's experience with it grows.'
Finally, here is our beloved first program to write in its second edition:
#include <stdio.h>
main()
{
printf("hello, world\n");
}