Printf()
function in C :
It is called as
formatted data output function.
The printf() function
,translates internal values as characters.
This function converts
, formats and displays arguments using standard output i.e the console .
The function can be
used to output any combination of numerical values, characters and strings .
The printf() function
is written as
printf(“control string”,arg1,arg2,…,argn);
where control string
refers to a string that contains formatting information and arg1…argn are arguments which represents the individual
data items to be displayed.
The control string consist
of two types of objects namely the ordinary characters and the conversion
specifications.
Ordinary characters are
nothing but those characters which will be displayed on the standard output
i.e. the monitor.
The conversion
specification is prefixed with the percentage sign(%) and followed by a
conversion character.
There must be exactly
the same number of arguments as there of format specifiers . The format specifiers and the arguments are
matched in order from left to right.
Between the % sign and the
conversion character ,the following may also be given ,however in order
specified. The list is as follows
· A
minus sign , this specifies that the converted argument be left justified.
· A
number which specifies the minimum fiels width .if lesser is input ,the value
is padded to the left or right so as to make up for the minimum display width.
· A
period(.) ,this seperates the field width from the precision.
· A
number which displays the maximum display length of the string in case of
character or number of digits after a decimal point in case of a floating point
value.
· An
h if the integer is to be printed as short and
an i
if specified as signed integer.
Example program:
Output:
Given below is the list
of conversion character list:
The following program
indicates how several different data types can be displayed using print
function.
%d indicates integer , %s indicates character string and %f indicates floating value.
a,b,c,d,e,f in hexadecimal systems represents the number 10 to 15,these letters can be displayed in either upper case or lower case using the %X or %x format specifiers respectively.
Example program to display in hexa decimal format:
output:
Thank you ...
for more similar posts : https://iamafutureprogrammer.blogspot.com
0 comments: