How would you set a variable to equal infinity (or any guaranteed largest number value) in C?
Another portable way to get maximum value of integer:
unsigned int uMax = (unsigned int)~0;
signed int iMax = (unsigned int)~0 >> 1;
~0 -> setting all bits to one>> 1 -> erasing sign bit, by shifting all bits to the right by one position(unsigned int) typecasting to unsigned int after bits inversion instead of using ~0U, because C doesn't have a suffix for short,char literals (everything smaller than int in general)So for biggest possible char value - just change in formula typecasting to
unsigned char and etc.
Simply just invert all bits once more in max signed int expression:
signed int iMin = ~((unsigned int)~0 >> 1);
That sets first sign bit to one and the rest bits - to zero