Jump to: navigation, search

The C Programming Language, 2nd Edition, by Kernighan and Ritchie
Exercise 1.01 on page 8

Run the "hello, world" program on your system. Experiment with leaving out parts of the program, to see what error messages you get.

Solution by Richard Heathfield

Murphy's Law dictates that there is no single correct answer to the very first exercise in the book. Oh well. Here's a "hello world" program:

#include <stdio.h>

int main(void)
  printf("hello, world\n");
  return 0;

Full program, unknown; public domain; past reviewers: none; current reviews: none

As you can see, I've added a return statement, because main always returns int, and it's good style to show this explicitly.

Here's a list of simple compile lines for a variety of popular compilers:

gcc -W -Wall -ansi -pedantic -o hello hello.c

Microsoft C, up to version 5.1
cl -W3 -Zi -Od -AL hello.c

Microsoft C,version 6, Microsoft Visual C++ 1.0, 1.5
cl -W4 -Zi -Od -AL hello.c

Microsoft Visual C++ 2.0 and later
cl -W4 -Zi -Od hello.c

Turbo C++
tcc -A -ml hello.c (I think)

Borland C++, 16 bit versions
bcc -A -ml hello.c

Borland C++, 32 bit versions
bcc32 -A hello.c

Personal tools
Personal tools