List of all format specifiers in C programming

In C programming we need lots of format specifier to work with various data types. Format specifiers defines the type of data to be printed on standard output. Whether to print formatted output or to take formatted input we need format specifiers. Format specifiers are also called as format string.

Here is a complete list of all format specifiers used in C programming language.
Format specifier Description Supported data types
%c Character char
unsigned char
%d Signed Integer short
unsigned short
int
long
%e or %E Scientific notation of float values float
double
%f Floating point float
%g or %G Similar as %e or %E float
double
%hi Signed Integer(Short) short
%hu Unsigned Integer(Short) unsigned short
%i Signed Integer short
unsigned short
int
long
%l or %ld or %li Signed Integer long
%lf Floating point double
%Lf Floating point long double
%lu Unsigned integer unsigned int
unsigned long
%lli, %lld Signed Integer long long
%llu Unsigned Integer unsigned long long
%o Octal representation of Integer. short
unsigned short
int
unsigned int
long
%p Address of pointer to void void * void *
%s String char *
%u Unsigned Integer unsigned int
unsigned long
%x or %X Hexadecimal representation of Unsigned Integer short
unsigned short
int
unsigned int
long
%n Prints nothing
%% Prints % character


Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

6 comments:

  1. Thank you for such a long list. I was searching for this.

    ReplyDelete
  2. Hello I have just started learning C programming and recently I learnt about format specifiers. But I am wondering for what reason do we use %n.

    ReplyDelete
    Replies
    1. Hii, Rakesh
      %n basically prints nothing. It takes a pointer to integer as an argument and stores the total number of characters printed so far.

      Example:
      int n;
      printf("Hello, World %n", &n);
      printf("Total characters printed = %d", n);

      Output: The above code will print the total number of characters printed till the first occurrence of %n i.e. 13.

      Delete
  3. good job bro.

    ReplyDelete
  4. Printf returns total no. of characters printed on stdout. We can also do it this way -

    int totalPrinted = 0;

    totalPrinted = printf("Hello, World\n");

    printf("%d\n",totalPrinted);

    ReplyDelete