stack - What does it mean to subtract '0' from a variable in C? -
void push(float[],float); here, st[] float data-type stack , exp[] char data-type array storing postfix expression.
push(st,(float)(exp[i]-'0')); i couldn't figure out purpose of (exp[i]-'0') section though. why subtracting '0'?
a character nothing more integer, value encoding of character.
in common encoding scheme, ascii, value e.g. character '0' 48, , value e.g. '3' 51. now, if have variable somechar containing character '3' , somechar - '0' it's same doing 51 - 48 result in value 3.
so if have digit read character somewhere, subtract '0' integer value of digit.
this works on other encodings, not ascii, because c specification says encodings must have digits in consecutive order.
Comments
Post a Comment