In C programming, a format specifier is a special character that is used to specify the type of data that will be printed or read in a formatted input/output operation.
Format specifiers are used in conjunction with the printf() and scanf() functions to format the input and output of data.
Here are some commonly used format specifiers in C:
Type | Format Specifier |
---|---|
int | %d, %i |
char | %c |
float | %f |
double | %lf |
short int | %hd |
unsigned int | %u |
long int | %ld, %li |
long long int | %lld, %lli |
unsigned long int | %lu |
unsigned long long int | %llu |
signed char | %c |
unsigned char | %c |
long double | %Lf |
printf() example:
In this code, the format specifiers %d and %f are used to print the integer and floating-point values of a and b, respectively.
scanf() example: