Why did we use INT_MAX for the minimum value and INT_MIN for the maximum value?
also if we interchange both the functions INT_MIN & INT_MAX the code gives use garbage value as the output can someone please explain why does that happen?
Usage of INT_MAX & INT_MIN
If you think logically, then INT_MAX is the maximum value, so to find minimum of two nos, you cannot compare one minimum value with other minimum value, there has to be some maximum value, like you compare any no suppose 5 with your INT_MAX, then definitely 5 would be minimum out of these, and then suppose you have a smaller value say 2, so now when u will compare 5 with 2, then 2 will be minimum value.
Same applies for INT_MIN as well , where to determine the maximum value, you need to compare it with the minimum value every time… because if you will use INT_MAX, then maximum value always will be INT_MAX only…
I hope this clears your doubt.
1 Like
Yes it surely does, thanks a lot!