Conversion Specifiers for for printf() and the Resulting Printed Output - C Language Basics

C examples for Language Basics:printf

Introduction

Conversion Output Specification
%a Floating-point number, hexadecimal digits and p-notation (C99/C11).
%A Floating-point number, hexadecimal digits and P-notation (C99/C11).
%c Single character.
%d Signed decimal integer.
%eFloating-point number, e-notation.
%EFloating-point number, e-notation.
%f Floating-point number, decimal notation.
%g Use %f or %e , depending on the value. The %e style is used if the exponent is less than -4 or greater than or equal to the precision.
%GUse %f or %E , depending on the value. The %E style is used if the exponent is less than -4 or greater than or equal to the precision.
%iSigned decimal integer (same as %d ).
%o Unsigned octal integer.
%p A pointer.
%sCharacter string.
%u Unsigned decimal integer.
%x Unsigned hexadecimal integer, using hex digits 0f .
%X Unsigned hexadecimal integer, using hex digits 0F .
%% Prints a percent sign.

Demo Code

#include <stdio.h>

#define PI 3.141593//from   w  ww  .  j  a v  a 2 s .  c  o  m

int main(void){
    int number = 7;
    float pies = 12.75;
    int cost = 7800;

    
    printf("The %d contestants ate %f berry pies.\n", number, pies);
    printf("The value of pi is %f.\n", PI);
    printf("Farewell! thou art too dear for my possessing,\n");
    printf("%c%d\n", '$', 2 * cost);
    
    return 0;
}

Result


Related Tutorials