C Format Specifiers (JNNC Technologies)


Format specifiers can be defined as the operators which are used in association with printf() function for printing the data that is referred by any object or any variable. When a value is stored within a particular variable then you cannot print the value stored in the variable straightforwardly without using the format specifiers. You can retrieve the data that are stored in the variables and can print them onto the console screen by implementing these format specifiers in a printf() function.
Format specifiers start with a percentage % operator and followed by a special character for identifying the type of the data.
There are mostly 6 types of format specifiers that are available in C.

List of format specifiers in C

Format specifierDescription
%dInteger Format Specifier
%fFloat Format Specifier
%cCharacter Format Specifier
%sString Format Specifier
%uUnsigned Integer Format Specifier
%ldLong Int Format Specifier

Integer Format Specifier %d

The %d format specifier is implemented for representing integer values. This is used with printf() function for printing the integer value stored in the variable.
Syntax:
printf("%d",<variable name>);

Float Format Specifier %f

The %f format specifier is implemented for representing fractional values. This is implemented within printf() function for printing the fractional or floating value stored in the variable. Whenever you need to print any fractional or floating data, you have to use %f format specifier.
Syntax:
printf("%f", <variable name>);

Character Format Specifier %c

The %c format specifier is implemented for representing characters. This is used with printf() function for printing the character stored in a variable. When you want to print a character data, you should incorporate the %c format specifier.
Syntax:
printf("%c",<variable name>);

String Format Specifier %s

The %s format specifier is implemented for representing strings. This is used in printf() function for printing a string stored in the character array variable. When you have to print a string, you should implement the %s format specifier.
Syntax:
printf("%s",<variable name>);

Unsigned Integer Format Specifier %u

The %u format specifier is implemented for fetching values from address of a variable having unsigned decimal integer stored in the memory. This is used within printf() function for printing the unsigned integer variable.
Syntax:
printf("%u",<variable name>);

Long Int Format Specifier %ld

The %ld format specifier is implemented for representing long integer values. This is implemented with printf() function for printing the long integer value stored in the variable.
Syntax:
printf("%ld",<variable name>);

0 Comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();