Optional independent variables for C-language functions

Source: Internet
Author: User

function: macro va_arg () is used to pass a variable-length argument list to a function.

    1. First, you must call Va_start () to pass a valid argument list va_list and the first argument of the function coercion. The first parameter represents the number of arguments that will be passed.
    2. Second, call Va_arg () to pass the argument list va_list and the type of the parameter that will be returned. The return value of Va_arg () is the current parameter.
    3. Again, repeat the call to all parameters Va_arg ()
    4. Finally, it is necessary to call Va_end () to pass va_list to the completion of the purge.

1#include <stdio.h>2#include <stdarg.h>3 intSumint, ... );4 5     intMainvoid ) 6 {7 8     9 Ten       intAnswer = SUM (4,4,3,2,1 ); One  Aprintf"The answer is%d\n", answer); -  -      the  -       return(0 ); -  - } +  -      +  A     intSumintnum, ...)  at { -  -       intAnswer =0; -  - va_list argptr; -  in va_start (argptr, num); -  to        for(; num >0; num-- ) +  -Answer + = Va_arg (Argptr,int ); the  * va_end (argptr); $ Panax Notoginseng       return(answer); -  the}

This code shows that they are 4+3+2+1.

Optional independent variables for C-language functions

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.