fredhead3968 fredhead3968
  • 21-12-2017
  • Computers and Technology
contestada

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

Respuesta :

tonb
tonb tonb
  • 21-12-2017
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.
Answer Link

Otras preguntas

Independence is a universal human need agree or disagree
When researchers ask long term couples about turning points that were especially meaningful, which type did most people select?
State and explain modern periodic table. ⊕⊕
Find the number that is four greater than three times its additive inverse.
Identify the factors of the terms of the expression. 3). 5+6a+11b4). 13m-2n​
Write the chemical symbols for three different atomic anions that all have 34 protons.
Round 3.802 to the nearest tenth.
An LPN makes $30,000 per year. The benefits cost for this position is 30% per employee. It takes 2 months for an LPN to become fully productive. This facility h
the sum of two rational number is minus 4 by know if one of them is 13 by 6 them find the other ​
person sold a housefor Rs 20,00,000 then he gets 5% commission. Findcommission amount .​