Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.