Hi,
I just started learning c/c++, and am asking this question out of pure curiosity.
Look at this code snippet:
#include <stdio.h>
int main()
{
int i=10;
short j=10;
unsigned int ui=10;
unsigned short uj=10;
printf("%i\n",i);
printf("%i\n",j);
printf("%d\n",i);
printf("%d\n",j);
printf("%i\n",ui);
printf("%i\n",uj);
printf("%d\n",ui);
printf("%d\n",uj);
return 0;
}
The output of this program is simply 8 "10"s
My question is this: What is the difference between %i and %d, and how does printf know in each case whether the variable being passed is signed or unsigned or a long or a short integer?
All I know is somehow it works, but I would be really interested to know where it gets this information from.
Thanks in advance.