Hello World in C
Write, compile and run your first C program, and learn what each line of Hello World does.
Every C program starts running at main. The smallest useful program prints a line of text with printf:
#include <stdio.h>brings in the standard input/output library, whereprintfis declared.int main(void)is where the program starts.voidmeans it takes no arguments.printf("Hello, World!\n");prints the text.\nis a newline.return 0;tells the operating system the program succeeded.
To build it on your own machine, save it as hello.c and run gcc -Wall hello.c -o hello, then ./hello. The -Wall flag turns on warnings, which catch many mistakes early.
Example
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
}
Output:
Hello, World!