In C programming language, values can be type integer, floating-point, single character, or sequence of characters. We use format specifiers in C to display values of a variable of a different type. 

C contains different format specifiers used in printf() and scanf() functions; in this tutorial, we will go through a few important and most commonly used format specifiers in our C programs.

Post Graduate Program: Full Stack Web Development

in Collaboration with Caltech CTMEEnroll Now
Post Graduate Program: Full Stack Web Development

Why Do We Use C Format Specifiers?

Format specifiers in C are used to take inputs and print the output of a type. The symbol we use in every format specifier is %. Format specifiers tell the compiler about the type of data that must be given or input and the type of data that must be printed on the screen.

Now that you have a brief idea of format specifiers in C, we have a few lists of format specifiers moving ahead.  

The Most Commonly Used Format Specifiers in C

The Most commonly used format specifiers are given below:

Format Specifiers 

Type of Output

%d or %i

A decimal integer or signed integer 

%c

Signed character 

%f

Signed float

%e

A floating-point number

%s 

A string or sequence of character 

%lf

double

%Lf

Long double 

%o

%u

Octal integer 

Short unsigned integer

%ld 

Long decimal integer

%x

Hexadecimal integer

%p

Print memory address in the hexadecimal form

We will go through a few examples that will help you understand how to use format specifiers in printf() and scanf() functions for a better understanding.

New Course: Full Stack Development for Beginners

Learn Git Command, Angular, NodeJS, Maven & MoreEnroll Now
New Course: Full Stack Development for Beginners

%d (Decimal Integer) Format Specifier 

#include <stdio.h>

int main()

{

    int a=50;

    printf("The integer value of a is %d \n",a);

    return 0;

}

Output:

Specifiers_In_C_1

%c (Character) Format Specifier

#include <stdio.h>

int main()

{

    char s;

    printf("Enter the character \n");

    scanf("%c",&s);

    printf("The character is: %c",s);

    return 0;

}

Output:

Specifiers_In_C_2

%f (Floating Point) Format Specifier

#include <stdio.h>

int main()

{

    float a=3;

    printf("The floating point of a is %f \n",a);

    return 0;

}

Output:

Specifiers_In_C_3

%e (Floating Pointer Number) Format Specifier

#include <stdio.h>

int main()

{

    float a=12.5;

    printf("The floating-point of a is %e \n",a);

    return 0;

}

Output:

specifiers_In_C_4

%s (String) Format Specifier

#include <stdio.h>

int main()

{

    char s[15]="simplilearn";

    printf("The string value of s is %s \n",s);

    return 0;

}

Output:

Specifiers_In_C_5.

%lf (Double) Format Specifier

#include <stdio.h>

int main()

{

    double d=12.5;

    printf("The double value of d is %lf \n",d);

    return 0;

}

Output:

Specifiers_In_C_6.

Full Stack Web Developer Course

To become an expert in MEAN StackView Course
Full Stack Web Developer Course

%o (octal integer) Format Specifier

#include <stdio.h>

int main()

{

    int oct=11;

    printf("The octal integer value of oct is %o \n",oct);

    return 0;

}

Output:

Specifiers_In_C_7

%x (Hexadecimal Integer) Format Specifier

#include <stdio.h>

int main()

{

    int h=14;

    printf("The hexadecimal value of h is %x \n",h);

    return 0;

}

Output:

Specifiers_In_C_8.

%p (Prints Memory Address) Format Specifier

To find the memory address that holds values of a variable, we use the %p format specifier, and it prints in hexadecimal form.

#include <stdio.h>

int main()

{

    int sum=0;

    printf("The memory address of sum is %p \n",&sum);

    return 0;

}

output:

Specifiers_In_C_9

With that, you can conclude this tutorial on Format Specifiers in C

If you're eager to gain the skills required to work in a challenging, rewarding, and dynamic IT role - we've got your back! Discover the endless opportunities through this innovative Post Graduate Program in Full Stack Web Development course designed by our partners at Caltech CTME. Enroll today!

Next Steps

"Data Structures in C" can be your next topic. So far, you have learned why we use format specifiers in C. The next fundamentals will be the data structures and the varieties in data structures used for different purposes.

If you are interested in building a career in software development, then feel free to explore Simplilearn's Courses that will give you the work-ready software development training you need to succeed today. Are you perhaps looking for a more comprehensive training program in the most in-demand software development skills, tools, and languages today? If yes, our Post Graduate Program in Full Stack Web Development should be the right thing for your career. Explore the course and enroll soon.

Please let us know in the comment section below if you have any questions regarding the "Format specifiers in C ” tutorial. Our experts will get back to you at the earliest.

About the Author

Hoor Sania SHoor Sania S

Hoor is a Bangalore-based Research Analyst. She has a knack for learning computer languages and technologies. In her free time, she enjoys dancing and singing.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.
  • *According to Simplilearn survey conducted and subject to terms & conditions with Ernst & Young LLP (EY) as Process Advisors