Doubt with% i [duplicate]

0

I know that with% i you can read numbers in decimal, hexadecimal, and octal, but when I type 0x15, the number 21 appears, being fifteen that was to appear or am I wrong?

Example below

#include <stdio.h>

int main(int argc, char** argv)
{
   int n = 0x15;
   printf("%d\n",n);
  return 0;
}
    
asked by anonymous 01.05.2018 / 20:18

1 answer

2

0x15 in hexa = 21 in decimal.

The specifiers% i and% d are interpreted in the same way by the functions of the fprintf () family, but are interpreted differently by the fscanf () function family.

Using% d implies that the value entered by the user will be interpreted as a decimal integer.

Using% i allows the user to enter values on the basis of 8, 10, and 16.

When you type printf you use% d, so the result was in decimal.

    
01.05.2018 / 20:25