In C, format specifiers are used with functions like printf()
and scanf()
to control the input and output format of variables. Below are some commonly used format specifiers:
-
%d
or%i
: Used for printing or reading integers. -
%f
: Used for printing or reading floating-point numbers (e.g.,float
ordouble
). -
%c
: Used for printing or reading a single character. -
%s
: Used for printing or reading a string. -
%lf
: Used for printingdouble
values (floating-point numbers with double precision). -
%x
: Used for printing integers in hexadecimal format.
Each format specifier is used to correctly interpret and print the corresponding type of data. These specifiers help control how the data is represented in the output.