Formatted Input and Output


Formatted Input and Output


scanf() :-
The formatted input refers to input data that has been arranged in a particular format. Input values are generally taken by using the scanf function. The scanf function has the general form. 
            scanf (“control string”, arg1, arg2, arg3 …………,argn);

The format field is specified by the control string and the arguments arg1, arg2, ….argn specifies the address of location where address is to be stored. The control string specifies the field format which includes format specifications and optional number specifying field width and the conversion character % and also blanks, tabs and new lines. 

printf() :-
The printf ( ) function is quite flexible. It allows a variable number of arguments, labels and sophisticated formatting of output. The formatted output refers to output data that will be printed in screen. Output values are generally printed by using the printf function. The printf function has the general form:
printf (“conversion string”, variable list);

Conversion Strings and Specifiers:

        The conversion string includes all the text labels, escape character and conversion specifiers required for the desired output. The variable includes all the variable to be printed in order they are to be printed. There must be a conversion specifies after each variable.


Specifier Meaning


%c – Print a character 
%d – Print a Integer 
%i – Print a Integer 
%e – Print float value in exponential form. 
%f – Print float value 
%g – Print using %e or %f whichever is smaller 
%o – Print actual value 
%s – Print a string 
%x – Print a hexadecimal integer (Unsigned) using lower case a – F
%X – Print a hexadecimal integer (Unsigned) using upper case A – F 
%a – Print a unsigned integer. 
%p – Print a pointer value 
%hx – hex short 
%lo – octal long 
%ld – long

%ld – double

No comments:

Post a Comment