I have a small problem in my code for finding the minimum value from a series of numbers. When I initialize min = 0
, the minimum value turns out as 0. But when I do
If you don't initialize a local variable, its value is indeterminate, and using that will lead to undefined behavior.
What you should do is initialize it to a large value, just like you initialize max
to a small value. Use INT_MAX
from the
Also, if your variables can't be negative, you should probably use unsigned int
, and initialize min
to UINT_MAX
.