C Programming - Variable Number of Arguments - Discussion
Discussion Forum : Variable Number of Arguments - Find Output of Program (Q.No. 1)
1.
What will be the output of the program?
#include<stdio.h>
#include<stdarg.h>
void fun(char *msg, ...);
int main()
{
fun("IndiaBIX", 1, 4, 7, 11, 0);
return 0;
}
void fun(char *msg, ...)
{
va_list ptr;
int num;
va_start(ptr, msg);
num = va_arg(ptr, int);
num = va_arg(ptr, int);
printf("%d", num);
}
Discussion:
34 comments Page 3 of 4.
Yogeshwar Singh said:
1 decade ago
What is the meaning of attach ptr with pointer and why we need to do so ?
va_start(ptr, msg); /* attach ptr with msg */
va_start(ptr, msg); /* attach ptr with msg */
ALEX said:
1 decade ago
Why we use ... (only 3 dots) for variable arguments?
Raman kumar said:
1 decade ago
I think num = va_arg(ptr, int);
Keep the value 6 in num and this statement num = va_arg(ptr, int); hold 1 as it is true.
Keep the value 6 in num and this statement num = va_arg(ptr, int); hold 1 as it is true.
Sri lakshmi said:
1 decade ago
What is va_arg() do?
Vandana said:
10 years ago
Va_list ptr;
Va_list is not struct name than why we are creating a new pointer of Va_list type.
What is this? Is any data type?
Is Va_start is builtin function?
I am very confused please tell me the every thing in a proper manner.
Va_list is not struct name than why we are creating a new pointer of Va_list type.
What is this? Is any data type?
Is Va_start is builtin function?
I am very confused please tell me the every thing in a proper manner.
Supriya said:
10 years ago
The C library macro type va_arg(va_list ap, type) retrieves the next argument in the parameter list of the function with type.
Suhas said:
9 years ago
1. There are three macros available in file "stdarg.h" --->.
- va_start: is used to initialize the pointer to the beginning of the list of optional arguments.
- va_arg: is used to advance the pointer to next argument *.
- va_list: va_list is like any other type.
- va_start: is used to initialize the pointer to the beginning of the list of optional arguments.
- va_arg: is used to advance the pointer to next argument *.
- va_list: va_list is like any other type.
Kowshik said:
9 years ago
How to work this?
Please anyone explain me clearly.
Please anyone explain me clearly.
Pranoti said:
8 years ago
Good explanation @Shiv.
Suraj chavan said:
8 years ago
@All.
What was the answer to this code?
Please explain it with the answer.
#include<stdio.h>
Void main()
{
char CHAR='\328';
char CHAR1='\323'
printf("CHAR=%d\n CHAR1=%d\n",CHAR,CHAR1);
}
What was the answer to this code?
Please explain it with the answer.
#include<stdio.h>
Void main()
{
char CHAR='\328';
char CHAR1='\323'
printf("CHAR=%d\n CHAR1=%d\n",CHAR,CHAR1);
}
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers