C Programming - Variable Number of Arguments - Discussion

Discussion Forum : Variable Number of Arguments - Point Out Errors (Q.No. 7)
7.
Point out the error in the following program.
#include<stdio.h>
#include<stdarg.h>
void varfun(int n, ...);

int main()
{
    varfun(3, 7, -11.2, 0.66);
    return 0;
}
void varfun(int n, ...)
{
    float *ptr;
    int num;
    va_start(ptr, n);
    num = va_arg(ptr, int);
    printf("%d", num);
}
Error: too many parameters
Error: invalid access to list member
Error: ptr must be type of va_list
No error
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
16 comments Page 2 of 2.

Ratna said:   8 years ago
Please explain in briefly.

Rathika said:   7 years ago
Please explain the program briefly.

Lotus said:   7 years ago
As the number of arguments passed to varfun is infinite which is unpredictable.

So memory space is not allocated.

Zeus said:   7 years ago
The function varfun() can take only int type parameters but we are sending float type parameters too.

So shouldn't the Error be too many parameters.

Nithya said:   7 years ago
Please explain the answer.

Priya said:   7 years ago
Explain what is the function of va_list()?


Post your comments here:

Your comments will be displayed after verification.