C Programming - Variable Number of Arguments - Discussion

Discussion Forum : Variable Number of Arguments - Point Out Errors (Q.No. 6)
6.
Point out the error in the following program.
#include<stdio.h>
#include<stdarg.h>
void display(char *s, ...);
void show(char *t, ...);

int main()
{
    display("Hello", 4, 12, 13, 14, 44);
    return 0;
}
void display(char *s, ...)
{
    show(s, ...);
}
void show(char *t, ...)
{
    int a;
    va_list ptr;
    va_start(ptr, s);
    a = va_arg(ptr, int);
    printf("%f", a);
}
Error: invalid function display() call
Error: invalid function show() call
No error
Error: Rvalue required for t
Answer: Option
Explanation:
The call to show() is improper. This is not the way to pass variable argument list to a function.
Discussion:
11 comments Page 2 of 2.

Raj said:   1 decade ago
I couldn't understand why show() is improper. Can anyone please explain?


Post your comments here:

Your comments will be displayed after verification.