Wednesday, 23 June 2010

Format Specifiers

Format Specifiers in C language tells us which type of data to store and which type of data to print.This statement tells us that it is used in only 2 places

It performs following tasks

(1) Taking Input
(2)Displaying Output

Here is an example

int a=2;
 printf( ” %d “, x );

Output

2

Function printf of c language does not know what it has to print either it is and integer or float or long variable. What %d does is that it tells the function printf that it is an integer type variable.And a in function printf tells it to print the integer value from the variable named ‘a’.

Where % indicates conversion specification.


Format specifier         
            Characters matched
Argument type

%c      

any single character
            Char
%d, %i           
Integer
            integer type

%u      

Integer
            unsigned
%o      

octal integer
            unsigned
%x, %X          

hex integer
            unsigned
%e, %E, %f, %g, %G

floating point number
            floating type
%p      

address format
            void *
%s      
any sequence of non-whitespace characters
            char


You may like the following posts:


No comments:

Post a Comment