I'm a little confused about how printf handles ascii characters.
When I print the% character like this, I get the correct answer, like "ascii%", and thatβs fine.
printf("ascii %% \n"); printf("ascii \x25 \n"); printf("ascii %c \n", 0x25); ascii %
And I can put them on one line like this, and I get "ascii %%", and that is fine too.
printf("ascii %c \x25 \n", 0x25); ascii % %
But I can't do it in a different order, since then I get c, not%, like this "ascii% c"
printf("ascii \x25 %c \n", 0x25); ascii %c
What's happening?
However, I noticed that it seems that printf treats \ x25 as a regular% sign since if I add another% immediately after the exit (\ x25%), it will become what I expect.
printf("ascii \x25% %c \n", 0x25); ascii % %
But then I also noticed that printing one% also works, but I did not expect this.
printf("ascii % \n"); ascii %
Why is this work, I thought that one% is not a valid contribution to printf ... Can anyone clarify how printf should work?
Note. I use gcc by default for Ubuntu 12.04 (gcc version 4.6.3).