Hello, world

suggest change

Save this program as hello.c:

#include <stdio.h>

int main(void)
{
    puts("Hello, world");
    return 0;
}

#include <stdio.h> makes the declaration of puts available. A header can also declare types and define macros; including it does not itself link a library into the program.

int main(void) defines the entry point for a hosted C program. The void parameter list states that this form of main accepts no arguments. The returned int communicates termination status to the host environment. Returning zero indicates success.

puts writes the string to the standard output stream and appends a newline. The semicolon terminates this expression statement. Many C statements end with a semicolon, but compound statements and control structures such as if (...) { ... } do not take one after the closing brace.

Compile and run

With GCC:

gcc -std=c23 -Wall -Wextra -pedantic hello.c -o hello

With Clang:

clang -std=c23 -Wall -Wextra -pedantic hello.c -o hello

On a Unix-like shell, run the resulting program with:

./hello

Microsoft's compiler uses different options:

cl /std:clatest /W4 hello.c

Language-version support and option names vary by compiler release. If C23 mode is unavailable, select the newest standard supported by the implementation; this example is also valid in much older C versions.

The expected output is:

Hello, world

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents