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
You must initialize min
with a large number, otherwise 0
might remain as the smallest number.
You can initialize min
as
int min = INT_MAX;
INT_MAX
is the largest value that can be held by an int
( Must add
for INT_MAX
).
If you don't initialize min
with a value, then it will have an indeterminate value, which can be anything, so always initialize your local variables before using their values..