What is %i (what is that format specifier?) - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

What is %i (what is that format specifier?)

explain

%i

to me


Comments

  • : explain

    : %i

    : to me




    %i is, aside from two characters, a format specifier for the printf and scanf family of C input-output routines. When it occurs in the 'format string' as the first parameter to printf and scanf, it instructs printf or scanf to look after the format string for data for substitution.


    If you use %i in scanf for example, it will look for a pointer-to-int that must come after the format string in the parameter list you give it. Usually you do this by taking the address of an integer variable you already have. In printf, it means that an int follows in the parameter list, and that the value of the integer should be printed out in place of the %i.


    C allows %d as an alternative to %i.


    For example:


    int i;

    float f;

    double d;

    short s;


    scanf("%i%f%lf%hd",&i,&f,&d,&s);

    printf("%i%f%lf%hd",i,f,d,s);




    This just goes to show that all of the basic C numerical types have their own format code.




Sign In or Register to comment.