← Exercises|

Your first C program

Next
Write1 of 14 · about 4 min

Your first C program

Every C program starts at a function called main. When main returns, the program ends, and the number it returns is the exit status the operating system sees — 0 means "nothing went wrong".

printf writes text to the terminal. It lives in the standard input/output library, so a program that uses it has to say #include <stdio.h> at the top. Without that line a real compiler warns you, and then does something you did not ask for.

The \n at the end of a string is a newline. C does not add one for you: without it the next thing printed continues on the same line.

Example

#include <stdio.h>

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

prints: "Hello, World!\n"

Four things to notice: the include, the return type of main, the semicolon, and the \n.

Your task

Print exactly two lines: Hello, C. and then I am learning systems programming.

Stuck?

Explain it

What would happen if you left out the \n at the end of the first string?

Not graded — this is for you.

Where this goes

Project 1 asks you to write and compile this program yourself, then look at what each stage of the compiler produced. You have just written the source; the project is about what happens to it next.