C/C++ Arena

Step 2 of 5

Printing your own text

A piece of text in double quotes, like "I like pizza", is called a string literal. printf prints it exactly as written: every letter, space and capital. The double quotes themselves are not printed; they only mark where the text starts and ends.

#include <stdio.h>

int main(void) {
    printf("C was created in 1972\n");
    printf("   spaces   are   kept\n");
    return 0;
}
C was created in 1972
   spaces   are   kept

Statements and semicolons

Each instruction inside main is a statement, and in C every statement ends with a semicolon ;, the way a sentence ends with a period. The compiler uses the semicolons to tell where one instruction stops and the next begins. Line breaks don't matter to it: you could put two statements on one line, but one per line is much easier to read.

Why exact output matters

The tests on this site compare your program's output with the expected output character by character (ignoring only spaces at the ends of lines and blank lines at the very end). Real programs work the same way: another program reading your output, or a grader at work, won't guess what you meant. I am learning c is not the same as I am learning C.

Your turn: make the program print exactly:

I am learning C

Previous: Your first program Next: Several lines