C Programming - Variable Number of Arguments - Discussion
|
|
|
|
Read more:"Actions speak louder than words."
- (Proverb)
|
| 5. |
What will be the output of the program?
#include<stdio.h>
#include<stdarg.h>
void fun1(int num, ...);
void fun2(int num, ...);
int main()
{
fun1(1, "Apple", "Boys", "Cats", "Dogs");
fun2(2, 12, 13, 14);
return 0;
}
void fun1(int num, ...)
{
char *str;
va_list ptr;
va_start(ptr, num);
str = va_arg(ptr, char *);
printf("%s ", str);
}
void fun2(int num, ...)
{
va_list ptr;
va_start(ptr, num);
num = va_arg(ptr, int);
printf("%d", num);
}
|
| [A]. |
Dogs 12 | [B]. |
Cats 14 | | [C]. |
Boys 13 | [D]. |
Apple 12 |
Answer: Option D
Explanation:
No answer description available for this question.
|
|
Nivethi said:
(Tue, Nov 30, 2010 05:38:11 AM)
|
|
| |
| How the ans comes? |
|
Udaya said:
(Wed, Dec 1, 2010 12:29:24 AM)
|
|
| |
| First function calls the zeroth argument and first integer 12 is called. |
|
Revathi said:
(Wed, Jul 6, 2011 07:37:53 AM)
|
|
| |
| I didn't understand. |
|
Bablu said:
(Fri, Aug 5, 2011 07:53:03 PM)
|
|
| |
| I too didn't understand. |
|
Sujatha said:
(Sat, Sep 3, 2011 03:56:39 PM)
|
|
| |
In first function it call the string so apple is printed.
In second function it calls the 2nd argument i.e., 12. |
|
|