Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    C Format Specifiers

    Format specifiers can be defined as the operators associated with the printf() function for printing the data referred to by any object or any variable. When a value is stored in a particular variable, you cannot print the value stored in the variable straightforwardly without using the format specifiers. You can retrieve the data stored in the variables and print them onto the console screen by implementing these format specifiers in a printf() function.

    Format specifiers start with a percentage % operator and are followed by a unique character for identifying the data type.

    There are mostly six types of format specifiers that are available in C.

    List of format specifiers in C

    Format Specifier Description
    %d Integer Format Specifier
    %f Float Format Specifier
    %c Character Format Specifier
    %s String Format Specifier
    %u Unsigned Integer Format Specifier
    %ld Long Int Format Specifier

    Integer Format Specifier %d

    The %d format specifier is implemented for representing integer values. The printf() function is used to print the integer value stored in the variable.

    Syntax:

    printf("%d",<variable name>);

    Float Format Specifier %f

    The %f format specifier is implemented for representing fractional values. It is implemented within the printf() function for printing the fractional or floating value stored in the variable. You must use the %f format specifier whenever you need to print any fractional or floating data.

    Syntax:

    printf("%f", <variable name>);

    Character Format Specifier %c

    The %c format specifier is implemented for representing characters. It is used with the printf() function for printing the character stored in a variable. You should incorporate the %c format specifier when you want to print character data.

    Syntax:

    printf("%c",<variable name>);

    String Format Specifier %s

    The %s format specifier is implemented for representing strings. It is used in the printf() function for printing a string stored in the character array variable. When you have to print a string, you should implement the %s format specifier.

    Syntax:

    printf("%s",<variable name>);

    Unsigned Integer Format Specifier %u

    The %u format specifier is implemented for fetching values from the address of a variable having an unsigned decimal integer stored in the memory. It is used within the printf() function for printing the unsigned integer variable.

    Syntax:

    printf("%u",<variable name>);

    Long Int Format Specifier %ld

    The %ld format specifier is implemented for representing long integer values. It is implemented with the printf() function for printing the long integer value stored in the variable.

    Syntax:

    printf("%ld",<variable name>);


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.