Skip to content
AgileLogics
5 min read

Your First C Program

Prerequisites: Installing a C compiler

Create a file named hello.c:

#include <stdio.h>

int main(void) {
    printf("Hello, world!\n");
    return 0;
}

Compile and run it from the terminal:

gcc hello.c -o hello
./hello

Common mistakes

  • Forgetting return 0; — most compilers allow this and assume 0 (success) automatically in main, but writing it explicitly makes the program's intent clear.
  • Missing the #include <stdio.h> line — printf is declared in that header; without it, the compiler doesn't know what printf is.

Practice

Change the program to print your own name instead of "Hello, world!".

Show solution
#include <stdio.h>

int main(void) {
    printf("Ada\n");
    return 0;
}