CC · Lesson 1 of 8
Hello, World!
The original Hello World was written in C in 1974 by Brian Kernighan. We're still writing it today. This is either a testament to C's longevity or our lack of creativity.
C programs start with #include directives for headers, followed by functions. The main() function is the entry point. printf() from <stdio.h> prints formatted output to the terminal.
Compile with gcc hello.c -o hello, then run with ./hello. The -o flag specifies the output filename. main() returns an int — 0 means success, non-zero means error. The \n is a newline escape sequence; printf() doesn't add one automatically.
◆ Note
The return 0; at the end of main() tells the operating system the program ran successfully. You can omit it in C99 and later, but it's good practice to be explicit.
The return 0; at the end of main() tells the operating system the program ran successfully. You can omit it in C99 and later, but it's good practice to be explicit.