CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
How can send unlimited no of arguments to a function, eg printf function can take any no of arguments


Category C Interview Questions
Rating (4.9) By 21 users
Added on 7/19/2006
Views 2183
Rate it!
Answers:

using va_list variables in stdarg.h headerfile



Sending the unlimited number of arguments to a function can be done by "Variable number of arguments" concept in C.

These function definitions will contain an ellipse(...) which indicates the variable number of argument. example

#include <stdio.h>
#include <stdarg.h>

void eprintf (const char *template, ...)
{
va_list ap;
extern char *program_invocation_short_name;

fprintf (stderr, "%s: ", program_invocation_short_name);
va_start (ap, template);
vfprintf (stderr, template, ap);
va_end (ap);
}

Here va_Start() initializes variable argument list pointer ap to the beginning of the variable argument list, before any calls to va_arg().

The va_arg() macro returns the next argument in the variable argument list pointed to by ap.


For a clear example refer :
http://www.linuxvalley.it/encyclopedia/ldp/manpage/man3/stdarg.3.php



 Posted by: Syed Baseer Ahmed    

Contact Syed Baseer Ahmed  Contact Syed Baseer Ahmed


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What is the draw back in using friend function in c++
View Answer
In the following code, in which order the functions would be called?
x = f1(23,14)*f2(12/4)+f3();

a) f1, f2, f3
b) f3, f2, f1
c) The order may vary from compiler to compiler
d) None of the above

View Answer
What is the type of the variable b in the following declaration?
#define FLOATPTR float*
FLOATPTR a,b;

a) float
b) float pointer
c) int
d) int pointer

View Answer
A switch statement cannot include

a) constants as arguments
b) constant expression as arguments
c) string as an argument
d) None of the above

View Answer
What do you mean by normalisation of pointers

View Answer
How to convert Stack in to Queue and v varsa ?
c with data structure.

View Answer
What would be the output of the following program?
main()
{
const int x=5;
int *ptrx;
ptrx=&x;
*ptrx=10;
printf("%d",x);
}


View Answer
According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments?

View Answer
Would the following program compile?

main()
{
int a=10,*j;
void *k;
j=k=&a;
j++;
k++;
printf("n%u%u",j,k);
}




View Answer
If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?

main(int argc, char *argv[])
{
printf("%c",*++argv[1]);
}




View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/6038/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.69