Variable parameter list

Source: Internet
Author: User

In C + + there is a function overload, in C there is a variable parameter list, the STDARG macro implementation is defined in the <stdarg.h> header file, there are 3 macros:va_start(va_list variable name , The last named argument before the ellipsis ) is used for initialization,va_arg(variable name of va_list , variable parameter type ) for removing variable parameters,va_end(VA _list variable name ) is used to indicate the end value, declaring a variable of type va_list, such as ARG, with va_list

#include <stdio.h> #include <stdarg.h>float average (int val,...) {    va_list arg;    int count;    float sum = 0;    Va_start (arg,val);    for (count = 0;count < val;count++)    {        sum + = Va_arg (Arg,int);    }    Va_end (ARG);    return sum/val;} averaging int main () {    printf ("%f\n", average (5,1,2,3,5,6));    return 0;}


Variable parameter list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.