Format Specifiers in C Language

Format specifiers are special characters that are used in C language to format the output that is printed on the screen. They represent the type of data that will be printed. The format specifiers are used in conjunction with the printf() and scanf() functions. In this tutorial, we will discuss the format specifiers in detail, along with code examples and a specifier table.

Format specifiers in C are used to specify the data type and format of input and output values. They help define how data should be displayed or read by functions like printf() and scanf(). In this tutorial, we will explore the commonly used format specifiers in C and their corresponding data types.

Format SpecifierDescriptionData Type
%dDecimal integerint
%ldLong integerlong
%lldLong long integerlong long
%uUnsigned decimalunsigned int
%luUnsigned longunsigned long
%lluUnsigned long longunsigned long long
%fFloating-point numberfloat
%lfDouble precision floatdouble
%cCharacterchar
%sStringchar *
%pPointer addressvoid *

The syntax for using format specifiers is as follows:

The format string is a string that contains one or more format specifiers, which are preceded by the '%' character. The arguments are the values to be printed on the screen, and their data type should match the corresponding format specifier.

Here is a code example that uses the format specifiers for different data types:

Output:

In this example, we declare different variables of different data types, and we use their respective format specifiers to print their values. The printf() function is used to print the values on the screen.