Conversion Specification

In C program, the function printf ( ) and scanf ( ) make use of conversion specification to specify the type and size of the data. Each conversion specification begin with percent sign ( % ).


Some conversion specification for printf ( )

Conversion
Character

Meaning
%cprint a single character
%d, %iprint a decimal integer
%uprint an unsigned decimal integer
%oprint an unsigned octal integer
%xprint an unsigned hexadecimal integer using a,b,c,d,e,f
%Xprint an unsigned hexadecimal integer using A,B,C,D,E,F
%fprint a floating point (by default 6 digits printed after the .
%e print a floating number in exponential format
%Esame as %e. but it print E for exponent
%gprint a floating number in %f or %e format
%Gprint a floating number in %F or %E format
%sprint a string
%%print a % sign
%pprint a pointer in hexadecimal format


Some conversion specification for scanf ( )

Conversion
Character
Meaning
%cread a single character
%dread a decimal integer
%iread a signed integer, base is decided by the prefix number
read a signed hexadecimal integer if prefix is 0x
read a signed octal integer if prefix is 0
otherwise read a signed decimal integer
%uread an unsigned decimal integer
%oread an unsigned octal integer
%x, %Xread an unsigned hexadecimal integer
%fread a floating point number
%e, %Eread a floating point number
%g, %Gread a floating point number
%sread a string

Some valid conversion specifications are %ld, %hd, %Lf, %hx.

The modifier h can be used before conversion d, i, o, u, x, X to specify short integer and the modifier l can be used before d, i, o, u, x, X to specify a long integer. 

The modifier l can be used before conversion f, e, E, g, G to specify double and the modifier L can be used before f, e, E, g, G to specify a long double.