Hi, could anybody explain to me why the code below outputs "5050"? I'm having huuuge problems understanding the whole deal with char. I just don't get it at all.
The way I see it, "c = '1' + 1;" means c is currently 1, but not the ASCII code, but the actual character 1, because of ' '. Then you add 1 to it, which now makes it character 2.
After that it's a blank. How does it suddenly become 5050?
Thanx!
Code:
#include <stdio.h>
int main() {
char c;
c = '1' + 1;
switch (c) {
case '1': printf ("%d", c);
case '2': printf ("%d", c);
case '3': printf ("%d", c);break;
default: printf ("default");
}
return 0;
}