Which header file includes a function for the variable number of arguments?

By Priyanshu Vaish|Updated : June 22nd, 2022

Which header file includes a function for the variable number of arguments?

  1. stdio.h
  2. stdlib.h
  3. stdarg.h
  4. varagrg.h

Answer- C. stdarg.h 

The stdarg.h header file includes a function for the variable number of arguments.

Solution

Let us look at the answer to the question- Which header file includes a function for the variable number of arguments? In C language, if we are going to develop or declare a function that can accept a variable number of arguments, then the standard library header is included in that code. The standard library header that we use is stdarg.h.

The example of the stdarg.h header file includes a function for the variable number of arguments is as follows:

#include<stdio.h>

#include<stdarg.h>

void fun(char *msg, ...);

int main()

{

 fun("BYJUSEXAM", 1, 4, 7, 11);

 return 0;

}

void fun(char *msg, ...)

{

 va_list ptr;

 int num;

 va_start(ptr, msg);

 num = va_arg(ptr, int);

 num = va_arg(ptr, int);

 printf("%d", num);

}

The output of the above code is 4 as the first declaration of va_arg(ptr, int) assigns 1 to the num integer variable similarly, the second declaration va_arg(ptr, int) assigns 4 to the num integer variable.

☛ Related Questions:

Comments

write a comment

Follow us for latest updates