C Programming - Variable Number of Arguments - Discussion

Discussion Forum : Variable Number of Arguments - Point Out Errors (Q.No. 4)
4.
Point out the error in the following program.
#include<stdio.h>
#include<stdarg.h>

int main()
{
    void display(char *s, int num1, int num2, ...);
    display("Hello", 4, 2, 12.5, 13.5, 14.5, 44.0);
    return 0;
}
void display(char *s, int num1, int num2, ...)
{
    double c;
    char s;
    va_list ptr;
    va_start(ptr, s);
    c = va_arg(ptr, double);
    printf("%f", c);
}
Error: invalid arguments in function display()
Error: too many parameters
Error: in va_start(ptr, s);
No error
Answer: Option
Explanation:
We should have use va_start(ptr, num2);
Discussion:
11 comments Page 2 of 2.

Nagarjun said:   1 decade ago
Please explain the program.


Post your comments here:

Your comments will be displayed after verification.