Vote Up 0 Vote Down

comparing two characters in c



#‎define‬ gc getchar
int read_int() {
char c = gc();
while(c<'0' || c>'9') c = gc();
int ret = 0;
while(c>='0' && c<='9') {
ret = 10 * ret + c - 48;
c = gc();
}
return ret;
}


can anyone explain what c<'0' signifies i.e. how does comparison between two character occurs????
flag

Answers


Vote Up 0 Vote Down
ASCII value of char c < ASCII value of '0'. Just google ASCII value
flag | link |
Vote Up 0 Vote Down
Comparing 2 characters is basically comparing their ascii values. Hence if c holds any character whose ascii value is less than that of '0' then the expression c<'0' evaluates true else false.
flag | link |
Vote Up 0 Vote Down
Every character has its own ASCII value it basically compares the value of the variable so taken with the ASCII value of the character which is assigned to it.
flag | link |

Your Answer

Login before answering

Login with facebook