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.

Alok said:   1 decade ago
In C++ we have a scope to do it using inline functions but in C is doubt.

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

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

Shalini said:   1 decade ago
@rinku
va_list is a short cut for variable list..its an user defined data type!

Rinku Sharma said:   1 decade ago
What is the data type of ptr?

Here it is given as va_list.


Post your comments here:

Your comments will be displayed after verification.