C Programming - Variable Number of Arguments - Discussion

Discussion Forum : Variable Number of Arguments - Point Out Errors (Q.No. 2)
2.
Point out the error if any in the following program (Turbo C).
#include<stdio.h>
#include<stdarg.h>
void display(int num, ...);

int main()
{
    display(4, 'A', 'a', 'b', 'c');
    return 0;
}
void display(int num, ...)
{
    char c; int j;
    va_list ptr;
    va_start(ptr, num);
    for(j=1; j<=num; j++)
    {
        c = va_arg(ptr, char);
        printf("%c", c);
    }
}
Error: unknown variable ptr
Error: Lvalue required for parameter
No error and print A a b c
No error and print 4 A a b c
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
15 comments Page 2 of 2.

Nobody said:   1 decade ago
What is va_list and va_start ?

Anamika said:   1 decade ago
What is va_list and va_start?

Aashi said:   1 decade ago
Please give explanation.

Gsurav said:   1 decade ago
Why it didn't print 4?

Pooja said:   8 years ago
What is va_start?


Post your comments here:

Your comments will be displayed after verification.