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);
}
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.
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.
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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers