Skip to main content

Input/Output

printf function

In C, printf is an format function that prints the output on the screen (standard output). According to different data types in C, the parameters in printf are different, see the examples below.

The the header file #include<stdio.h> needs to be included before use printf.

Table 1: printf for basic data types.

data typeformatexample
int%dint i = 10;
printf("%d", i);
char%cchar c = "A";
printf("%c", c);
char[]%schar str[] = "Informatics-II"
printf("%s", str)

Table 2: The cursor control sequences for the printf command.

data typeformat
\ncarriage return and newline
\ttab