sarkinen.com > johan > Teaching > Programming
7. hello, world - Your First Program |
|
< 6. Tools - Editors, Compilers, ... | 8. Programming Constructs > |
This small and simple program presents a short text when executed and is very useful for multiple reasons.
Example 1: First known (1972) | Example 2: Modern, standard-conforming, C | |
main( ) { extrn a, b, c; putchar(a); putchar(b); putchar(c); putchar('!*n'); } a 'hell'; b 'o, w'; c 'orld'; |
#include <stdio.h> int main(void) { printf("hello, world\n"); return 0; } |
|
Example 3: In PHP | Example 4: In JavaScript | |
echo "hello, world"; |
document.write('hello, world'); |
The first known from 1972 is from Brian Kernighan's Tutorial Introduction to the Language B (a predecessor to C).
As you can see, the syntax varies a lot between the different languages.
putchar()
function in Bprintf()
function in C, which is imported (the #include
statement) from a library.echo
method in PHPdocument.write()
function in JavaScriptLearning programming languages means learning not only the specific syntax but also what libraries are available. You certainly don't want to write everything from scratch, but reuse other programmers' code as much as possible.
Ok, enough of reading - let's to some practicing! Remember - learning by doing.
document.write('hello, world'); |
If you don't see 'hello, world':
< 6. Tools - Editors, Compilers, ... | 8. Programming Constructs > |