I thought the following code might cause an overflow since a * 65535 is larger than what unsigned short int can hold, but the result seems to be correct.
Is there some built-in mechanism in C that stores intermediary arithmetic results in a larger data type? Or is it working as an accident?
unsigned char a = 30;
unsigned short int b = a * 65535 /100;
printf("%hu", b);
short inton your compiler? compiler usually use its native bitwidth for constant expresion evaluations so its most likely computed on 32 or 64 bits and the result is then truncated to target bitwidth... the same applies to float/double unless you explicitly cats type (1ull, ...1.0, 1.0f,... )