I'm trying to return the smallest value using va_args
, which supports multiple arguments, but it always returns the same number: -13227;
#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
int minimo(int args, ...)
{
int elemento, min;
va_list valist;
va_start(valist, args);
min = INT_MAX;
for(int i=0; i<args; i++)
{
elemento = va_arg(valist, int);
if(elemento < min)
min = elemento;
}
va_end(valist);
return min;
}
int main()
{
int num = minimo(8, 5, 3, 7, 12, 6);
printf("%d\n", num);
return 0;
}
And if you change the variable min
from int to unsigned int , it always returns 0.
link