Ask Question
12 January, 21:24

Write a program to test the difference between %d and %i conversion

+5
Answers (1)
  1. 12 January, 23:16
    0
    Void test (char * s)

    {

    int i, d;

    sscanf (s, "%i", &i);

    printf ("%s converts to %i using %%i/n", s, i);

    sscanf (s, "%d", &d);

    printf ("%s converts to %d using %%d/n", s, d);

    }

    int main ()

    {

    test ("123");

    test ("0x123");

    return 0;

    }

    outputs:

    123 converts to 123 using %i

    123 converts to 123 using %d

    0x123 converts to 291 using %i

    0x123 converts to 0 using %d

    As you can see, %i is capable of parsing hexadecimal, whereas %d is not. For printf they're the same.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program to test the difference between %d and %i conversion ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers