I was trying to implement function with variable arguments but was getting garbage values as output.I have referred this article before trying to implement on my own.Could anyone help me out with this code as I am unable to understand what's wrong in this code.
/* va_arg example */
#include <stdio.h> /* printf */
int FindMax (int n, ...)
{
int i,val,largest,*p;
p=&n;
p+=sizeof(int);
largest=*p;
for (i=1;i<n-2;i++)
{
p+=sizeof(int);
val=*p;
largest=(largest>val)?largest:val;
}
return largest;
}
int main ()
{
int m;
m= FindMax (7,702,422,631,834,892,104,772);
printf ("The largest value is: %d\n",m);
return 0;
}