CodeNest

Anatomy of a C program

C is compiled: your source is translated to machine code before it runs. Every program starts at main:

#include <stdio.h>      // gives us printf

int main(void) {
    printf("Hello, World!\n");
    return 0;           // 0 means "success"
}
  • #include pulls in a header with function declarations.
  • printf prints formatted text. \n is a newline – C does not add one for you.
  • Every statement ends with ;.

Try it

Make the program print:

Hello, C!
C unavailable
Next
Running C needs a server execution engine, which isn't configured on this deployment. You can still read the lesson and try the code locally.
Loading editor…

Press Ctrl/ + Enter or click Run to see the output here.