C Programming - Variable Number of Arguments - Discussion

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

int main()
{
    fun(3, 7, -11.2, 0.66);
    return 0;
}
fun(...)
{
    va_list ptr;
    int num;
    va_start(ptr, n);
    num = va_arg(ptr, int);
    printf("%d", num);
}
Error: fun() needs return type
Error: ptr Lvalue required
Error: Invalid declaration of fun(...)
No error
Answer: Option
Explanation:
There is no fixed argument in the definition fun()
Discussion:
8 comments Page 1 of 1.

Sushmitha said:   7 years ago
Why can't we declare the variable argument in the function?

Sathya.s said:   9 years ago
Please, explain me clearly.

Sathya.s said:   9 years ago
Please, explain me clearly.

Vishu said:   9 years ago
Yes, you are right @vishal.

Vishal said:   9 years ago
If we do not supply return type in c then the default return must be int in C.

Ishaan said:   10 years ago
Isn't the return type mentioning compulsory?

Swapna said:   1 decade ago
The called function should contain atleast 1 fixed argument
i.e fun( int num,...){ }

Balu said:   1 decade ago
Please explain me.

Post your comments here:

Your comments will be displayed after verification.