Format Specifier in C

Format specifiers can be described as an operator that is used to print the data referred by any object or variable in combination with the printf () function. Without using the format specifiers, even if a value is stored in a specific variable, you cannot print the value stored in the variable.

By implementing these format specifiers in a printf () function, you can retrieve the data stored in the variables and print them onto the console screen. Format specifiers start with a percentage operator and then have a special character to identify the type of data.

List of format Specifiers in C

Format Specifier Description
%f Float format specifier
%c Character format specifier
%s String format specifier
%d Integer format specifier
%o Unsigned octal number for integer
%u Unsigned integer format specifier

Float Format Specifier

The %f format specifier is implemented to reflect the fractional values. This is implemented within the function printf () to print the fractional or floating value stored in the variable. Whenever you need to print any data that is fractional or floating, use the %f format specifier.

Syntax:

Code:

Output:

Format Specifier in C

Character Format Specifier

To represent characters, the per cent c format specifier is implemented. This is used for printing the character stored in a variable with the function printf (). You should include the %c format specifier when you want to print character information.

Syntax:

Code:

`

Output:

Format Specifier in C

String Format Specifier

For the representation of strings, the percent s format specifier is implemented. This is used for printing a string stored in the character array variable in printf function. The %s format specifier should be implemented when you need to print a string.

Syntax:

Code:

Output:

Format Specifier in C

Integer Format Specifier

To represent integer values, the %d format specifier is implemented. It is used for printing the integer value stored in the variable with the function printf ().

Syntax:

Code:

Output:

Format Specifier in C

Unsigned Octal Number for Integer

The specifier for the %o format is implemented to display integer values. This is implemented with function printf () to print the octal number integer value stored in the variable.

Syntax:

Code:

Output:

Format Specifier in C

Unsigned Integer Format Specifier

For fetching values from the address of a variable having unsigned decimal integer stored in the memory, the %u format specifier is implemented. This is used for printing the unsigned integer variable inside the printf () function.

Syntax:

Code:

Output:

Format Specifier in C

Pin It on Pinterest

Share This