🎓 A1Learner
🔍
0 of 50 lessons completed

C Output

The syntax lesson named the parts of a program. Output is the text a program prints to the screen, and printf prints it.

Print one line

One printf prints one line of text. The \n at the end starts a new line.

#include <stdio.h>

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

Print on two lines

One printf can print two lines. Each \n starts a new line.

#include <stdio.h>

int main() {
  printf("First\nSecond\n");
  return 0;
}

Tab and quote

A \t moves to the next tab stop. A \" prints a double quote inside the string.

#include <stdio.h>

int main() {
  printf("Name:\tAda\n");
  printf("She said \"Hi\"\n");
  return 0;
}

Example

#include <stdio.h>

int main() {
  printf("Line one.\n");
  printf("Line two.\n");
  printf("Line three.\n");
  return 0;
}

Key points

  • printf prints the text inside its double quotes.
  • A \n moves the print to a new line.
  • The characters \t inside a string move to the next tab stop.
  • The characters \" inside a string print a double quote.
  • Two printf lines run in order.
  • Text in a program sits between double quotes.
  • A backslash starts a special code inside a string.

Three lines print in order. The output shows all three, one per line, because each ends with \n.

Note

A string cannot hold a plain double quote, so use \" for one.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Which two characters start a new line inside a string?