Variable parameter functions

Source: Internet
Author: User

The 1.C standard library has a set of macros that can be used to create variable parameter functions (functions that accept a variable number of parameters)

Example:

#include <stdarg.h>//contains the stdarg.h header file, which handles variable parameter functions#include <stdio.h>voidPrint_ints (intargs,...);//after args is a mutable parameter{va_list ap;//va_list to save variable parametersVa_start (Ap,args);//explains where mutable parameters start    inti;  for(i =0; I < args;i++) printf ("ragument:%i\n", Va_arg (AP,int));//Va_arg accepts two values, va_list and parameter typesVa_end (AP);//with Va_end, tell C to finish.}voidMain () {print_ints (3, -,101, +);}

2.va_end, Va_start is a macro, not a function

3. variable parameter function must have ordinary parameters, so that his name can be passed to Va_start

4. Cannot exceed the number of functions given when reading a parameter

5. Need to know the type of parameter to read

Variable parameter 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.