← The C Language Lesson 1 of 77 · 10 XP

How a C program is structured

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

C is a compiled language. You write the program's text (main.c), a compiler translates it into machine code, and only then is the resulting file run. Here the compiler is a real clang, running right in your browser.

A minimal program:

#include <stdio.h>

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

Line by line:

  • #include <stdio.h> — include the standard input/output header file. It declares printf.
  • int main(void) — the main function, where execution starts. int means it returns a whole number, void means it takes no arguments.
  • { ... } — the function body.
  • printf("...\n"); — output. \n is a line break. Every statement ends with ;.
  • return 0; — the exit code: 0 means "all good".

Unlike Python, indentation in C doesn't affect anything: blocks are marked by curly braces. But people indent anyway, so that the code is readable. In this course we use the K&R style: a function's opening brace goes on a new line, while for if and for it stays on the same line.

Task. Print two lines:

Hello, IGD!
I am learning C

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.