C-language function variable parameter list

Source: Internet
Author: User

C language allows the use of variable parameter list, our usual printf function is variable parameter function, C standard library provides stdarg.h to provide us with this support; the header file provides some types and macros to support variable parameter lists, including type va_list, Macro Va_start, VA _arg, Va_end;

Variable function parameter definition method:

#include <stdarg.h>void func (int count,...) {        va_list ap;        int IX, TMP;        Va_start (AP, a);                For (Ix=0;ix < count; ++ix) {                TMP = VA_ARG (AP, int);                Process the Param        }                va_end (AP);}    

The first parameter of the function, count, is essential, that is, you define a variable argument list function to have at least one parameter;

Va_list: It is generally defined as char *;

Va_start (va_list AP, Paramn): Initializes the value of the AP, pointing to the first mutable parameter

Va_arg (va_list AP, type): Will point from the AP according to the type to get the actual value and move the AP pointer

Va_end: Generally do not do anything

C-language function variable parameter list

Related Article

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.