Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

printf()

It is the major output function in C.


It is a predefined function available in
standard input output header file <stdio.h>
It is used to print the given text on the
monitor.
Printf() always refers standard output
device i.e. monitor.
 Printf performs both formatted and
unformatted output operations.
 In printf() the given content is printed as
it is except conversion and back slash
characters.
 Printf() returns an integer value that
indicates the no of printable characters
it is going to print on the screen.
(including spaces, conversion characters,
back slash characters,…)
 In printf() execution order is right to left
and printing is left to right.
 In printf() the first argument should be
in “ “.
syntax:
int printf( “ [text] [ conversion characters ]

format specifiers
[ , variable, variable, …+ * , expressions + );
Eg:
printf(“ Hello” );
int a=10;
float b=1.2;
printf(“a = %d”, a);  a=10
printf(“a=%d, b=%f”, a, b); a=10, b=1.2
printf(“Sum = %f”, a+b); sum=11.2
printf(“a = %d b = %f sum=%f”, a, b, a+b );
 a=10 b=1.2 sum=11.2
printf(“ %d + %f = %f ” ,a,b,a+b); 
10+1.2=11.2
printf(“%d”,a);  10
printf(“a=”);  a=
Output: Good evening
BACK SLASH / ESCAPE SEQUENCE CHARACTERS
They started with back slash [ \ ].
They used to format the outputs.
They participated in program execution but not
displayed in output. Hence they are also called
escape sequence characters.
Each back slash character=1 byte i.e. one character.
BACK SLASH CHARACTER DESCRIPTION
\a Alert [ beep sound ]
\b Back space
\n New line character
\t Tab space
\r Carriage return[beginning of
line]
\f
Form feed
\v Vertical tab
\0 Null char
\\ \ [ invalid ]
\k k [ invalid ]

You might also like