Printing Output

The printf function is used to print text on the screen. The data which we print on screen is a text or a variable.

  • If it is text, it is enclosed in quotation marks.
  • If it is variable, name of variable is written without quotation marks.

Note: Do not forget to put ; at the end

Adding line breaks

\n: it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line.

Different Escape Sequences

Escape SequenceDescriptionCode
\nNew lineprintf("\n");
\tTab - prints four spacesprintf("\t");
\aBeep soundprintf("\a");
\bBackspaceprintf("\b");
\fForm feedprintf("\f");
\rCarriage returnprintf("\r");
\\It adds backslashprintf("\\");
\'Single quoteprintf("\'");
\?Question markprintf("\?");
\0Null characterprintf("\0");

Printing Numbers

If we want to print numbers in C, we store them in variables then print variables on screen using %d (for integers). We will discuss about this in detail in variable section. Here is a brief example.

Note: If we write numbers in double quotes, these are not treated as numbers. Everything inside double quotation marks is a string literal which is text.

Printing Different Types of Variables

Printing data stores in variables is not our concern for now. This is just for overview. You do not need to understand it here. Just go through it once.

Practice Exercises

Complete these exercises to reinforce your learning and earn XP

Sign in to track your progress and earn XP!
Exercise 1 of 2Easy

Which of the following is a best practice in programming?

10 XP~2 min
Exercise 2 of 2Easy

Code that is easy to read and understand is called ___ code.

10 XP~2 min