Skip to content

Exercise 1 of 10 · Output

Hello, Out Loud

What you will make

A banner with your own name inside it, printed by a C program that you compiled and ran yourself.

The one new idea: printf() puts text on the screen

Almost every program you write from here on will show you something. printf() is how a C program talks back to you, and reading its output is how you check whether the program you wrote is the program you meant to write.

Go straight to the code ↓

What printf does

A compiled program does not tell you anything unless you ask it to. printf is how you ask.

Whatever sits between its double quotes is written to the screen exactly as it appears — every letter, every space, every symbol. C does not tidy any of it up and does not add anything you did not type, which includes the line break at the end. If you want the next thing you print to start on its own line, you write \n inside the quotes yourself.

That is the whole idea for now. There is a compiler translating your file into machine code behind the scenes, but none of that changes what printf does: it writes text, exactly as given.

A worked example

A different program, so the answer to this exercise is not given away:

C
#include <stdio.h>

int main(void) {
    printf("--> ready\n");
    printf("--> steady\n");
    printf("--> go\n");
    return 0;
}

Running that prints three lines:

Output
--> ready
--> steady
--> go

Three printf calls, three lines of output, in the order they appear in the file. Each call ends with \n, which is why each one lands on its own line rather than all three running together.

Your turn

The editor already holds a working program. It prints a banner: a row of = signs, two lines of text, then another row of = signs.

One thing is missing. The second line says YOUR NAME instead of your name.

Replace those two words with your own name, keep the quotes and the \n exactly where they are, and press Run.

That is the entire task. You are not expected to write a line from scratch yet.

If something goes wrong

If the compiler complains, it is almost always the quotes. The text you want printed has to sit between them — "Hello, Sam!\n" works, Hello, Sam!\n on its own does not, because without quotes the compiler reads Hello as the name of something in the program rather than as text to print, and it will not guess what you meant.

Nothing you do here can break anything permanently. Change it, run it, change it again.

Write your code

Runs in your browser. Press Run (or Ctrl/Cmd+Enter) and the output is checked for you.

Ctrl/Cmd+Enter to run

Press Esc then Tab to move keyboard focus out of the code editor.

Ready
Output will appear here after you run your code.

The runtime is starting in the background. You can type now — it will be ready before you are.

The answer appears here once you have run your code at least once.

Things that often go wrong here

Deleting the quotes along with the placeholder
Without quotes, the compiler reads YOUR and NAME as two names it has never heard of rather than as text, and it stops before anything runs, pointing at that line.
Deleting the \n at the end of the line
\n is what moves printing on to the next line. Without it, the banner's closing row of = signs gets glued onto the end of your greeting instead of starting a new line, because printf never adds a line break you did not ask for.
Changing the wrong line
Only the second printf line has a placeholder. The rows of = signs are the top and bottom of the banner and stay exactly as they are.

Longer explanation: read the full lesson. Want a blank editor instead? Open the C playground.