C Format Specifier

Format specifiers define the type of data. The value of a variable is stored in memory. So we can not directly print values of a variable from memory. Therefore C provides format specifier for printing values of variables that are stored in memory. C provide different types of format specifier for data types. Every format specifier starts with % percent sign.

Following is the list of format specifiers that can be used with the printf( ) function.

List of format specifiers in C

Data type Format Specifier
Integer short signed %d or %I
short unsigned %u
long signed %ld
long unsigned %lu
unsigned hexadecimal %x
unsigned octal %o
Real float %f
double %lf
Character signed character %c
unsigned character %c
String %s

Let’s see an example to demonstrate the use of format specifier:
Example:

Output:

The %f for printing real values, %d for printing integer values, %c for printing character values.
The format specifier does not print on the screen, it displays the value stored in variables.
In this way, you can also print a string using %s format specifier.

You can use this format specifier between expressions.
Also, these can use with scanf(). You will understand the purpose of each format specifier in the program in our next post.

 

Help others by sharing the content!

1 thought on “C Format Specifier”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.