vargs in c


Author: yifei / Created: May 29, 2017, 11:02 p.m. / Modified: May 29, 2017, 11:04 p.m. / Edit

int max(int n, ...) {
    va_list arg_pointer;
    int result = INT_MIN;

    va_start(arg_pointer, n);
    for (int i = 0; i < n; i++) {
        int arg = va_arg(arg_pointer, int);
        if (arg > result)
            result = arg;
    }
    va_end(arg_pointer);

    return result;
}     

Reference

  1. http://www.cnblogs.com/chinazhangjie/archive/2012/08/18/2645475.html

  2. http://wiki.jikexueyuan.com/project/c-advance/other.html


评论区