Codiqo

Learn C · lesson 1 of 60 · about 5 minutes

Hello, C

Start a system report, the kind of tool C is used for: print its first lines with printf() and fix your first compiler error.

What you'll learn

  • Explain what a compiler does
  • Write a main() function
  • Print text with printf() and \n

Talk to the machine

C is the language underneath almost everything: operating systems, the tools that tell you how full your disk is, even the program that runs Python. Learning C is learning how computers really work.

In this unit you'll write a system report, a small tool that tells you about the machine it runs on. C is compiled: a compiler turns your code into machine code that the processor runs directly, and it refuses to build anything it doesn't understand.

The report's first lines

#include <stdio.h>

int main(void) {
    printf("=== System report ===\n");
    printf("Machine: codiqo-box\n");
    return 0;
}

Output

=== System report ===
Machine: codiqo-box

Every part has a job

  • #include <stdio.h> brings in the standard input and output tools, including printf
  • int main(void) is where every C program starts
  • The curly braces { } hold the code that belongs to main
  • printf("...") prints text, and \n starts a new line
  • Every statement ends with a semicolon ;
  • return 0; tells the system the program finished successfully

printf only starts a new line when you ask

#include <stdio.h>

int main(void) {
    printf("Status: ");
    printf("OK\n");
    return 0;
}

Output

Status: OK

Tip

Forgetting \n is the most common beginner surprise in C: without it, the next printf carries on from the same line.

Now try it yourself

This lesson is free in Codiqo, with 7 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.