hamburger

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

By BYJU'S Exam Prep

Updated on: September 25th, 2023

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

#include

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:

Our Apps Playstore
POPULAR EXAMS
SSC and Bank
Other Exams
GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303 help@byjusexamprep.com
Home Practice Test Series Premium