Javatpoint Logo
Javatpoint Logo

va_start() in C programming

The va_start is a macro defined in the stdarg header file in the C Programming languages. The va_start() function is used to initialize the argument list.

The argument list is referred to by ap. Initializing the argument list is necessary before using the va_arg() and va_end() functions in the program. The second argument passed in the va_start() function is the last_arg. This argument is also called the fixed argument. This argument is passed in the function that is the argument before the ellipsis.

The macros are called in the program before calling the va_arg and va_end in the function.

Syntax for using va_start() function

The declaration for va-start() macro in your program:

Return Type in va_start() function

void: Since the function does not return any value, the return type used when declaring the va_start() function is void.

Parameters Passed in va_start() function

  • ap - This parameter refers to the variable list. It is an object that is specifically created for the va_list. This object is used for storing the information that the user requires to find the additional arguments using the va_arg() function.
  • last_arg - This is the last argument entered in the va_start() function. It is a fixed-length argument to be passed in it just before the ellipsis.

Header file:

Since this macro is defined in the stdarg library, thus, it is necessary to include the header file in your program

Implementation of va_start() function in C Program:

Output:

va_start() in C programming

Let us discuss another example of printing the product of a list of numbers.

Output:

va_start() in C programming

Conclusion: Before implementing the va_arg() function in the your program, it is necessary to implement the va_start() function in your code and end it with va_end() function.


Next TopicAscii vs Unicode





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA