The answer to your question is that, as many others have pointed out, you are using the lowest type of boolean instead of the number type, for example int , which would be in harmony with the rest of your program.
bool lowest;
Boolean types, as expected, can contain basically two states: true and false . For historical reasons (i.e., mainly because of C inheritance), logical values ββare associated with integers for which 0 means false, and any other value means true.
That's why the boolean type is still compatible with integers (this is the way to say it), and when you assign it to a null value, then it is false. If you assign it any other int value, it will act correctly. This happens on lines like this:
lowest = myNumbers[0];
Finally, when you do:
printf("\n%d", lowest);
The reverse process takes place, and true is converted to int (since you specified% d in the printf format string) and true is converted to 1, which is the default integer value for true in the bool type when its integer value is set: (int) true (in your program: (int) lowest ).
As you can imagine, in more than 90% of cases the input integer values ββwill be different from zero, so you get 1, regardless of the input.
source share