Let's explain this a bit more using integers instead of characters.
char c = 97; printf("%d", c - 48);
This, of course, will print 49, but as we move this character to the ASCII table, we get 1.
char c = 97; printf("%c", c-48);
This code now prints 1 because we use the char data type when printing and convert the value 49 to the equivalent ASCII number 1.
To prove this, we can try something like this.
char a = 'a'; char b = 97; if((a == b) && ((a-'0') == (b-48))) { printf("%s", "true"); }
First we see that a and b are equivalent, and then we see that a-'0 'is equivalent to b-48. Since both are true, we print true.
source share