C programming stdio.h function - int vprintf(const char *format, va_list arg)

The vprintf() function in the stdio.h library of C programming language is used to print the formatted output on the standard output stream stdout. It takes a variable-length argument list as input that is created by the va_start() and va_arg() functions from the stdarg.h library.

The function has the following syntax:

r‮t refe‬o:theitroad.com
int vprintf(const char *format, va_list arg);

Here, format is a character string that contains the format control string, and arg is the variable-length argument list created by va_start() and va_arg() functions.

The vprintf() function works similar to the printf() function, but it takes a va_list argument instead of a variable number of arguments. It reads the format string and the corresponding arguments from the argument list and writes the formatted output to the standard output stream stdout. The function returns the number of characters printed on success, and a negative value on failure.

Here's an example that demonstrates the use of the vprintf() function:

#include <stdio.h>
#include <stdarg.h>

int main() {
    char *name = "John";
    int age = 25;
    float salary = 2500.50;

    printf("Details of employee: \n");
    vprintf("Name: %s, Age: %d, Salary: %f\n", 
            va_arg, 
            name, 
            age, 
            salary);

    return 0;
}

In this example, the vprintf() function is used to print the details of an employee. The va_arg is the variable-length argument list created using the va_start() and va_arg() functions. The format string "Name: %s, Age: %d, Salary: %f\n" contains three format specifiers, which correspond to the three arguments in the variable-length argument list. The output of this program will be:

Details of employee: 
Name: John, Age: 25, Salary: 2500.500000