Printf can be implemented by using __________ list.
Answers were Sorted based on User's Feedback
Answer / sagar arora
variable length argument lists,for more information checked
out in Dennis Ritchie book.u can write ur own printf.
Is This Answer Correct ? | 6 Yes | 1 No |
Answer / navneet
using Variable length argument lists :
Let us see how
Use vprintf, vfprintf, or vsprintf.
Here is an "error" routine which prints an error message, preceded by the string "error: " and terminated with a newline:
#include <stdio.h>
#include <stdarg.h>
void
error(char *fmt, ...)
{
va_list argp;
fprintf(stderr, "error: ");
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
va_end(argp);
fprintf(stderr, "\n");
}
To use the older <varargs.h> package, instead of <stdarg.h>, change the function header to:
void error(va_alist)
va_dcl
{
char *fmt;
change the va_start line to
va_start(argp);
and add the line
fmt = va_arg(argp, char *);
between the calls to va_start and vfprintf. (Note that there is no semicolon after va_dcl.)
References: K&R II Sec. 8.3 p. 174, Sec. B1.2 p. 245; H&S Sec. 17.12 p. 337; ANSI Secs. 4.9.6.7, 4.9.6.8, 4.9.6.9 .
Is This Answer Correct ? | 1 Yes | 0 No |
int DIM(int array[]) { return sizeof(array)/sizeof(int ); } main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr)); }
Is the following code legal? struct a { int x; struct a b; }
main(int argc, char **argv) { printf("enter the character"); getchar(); sum(argv[1],argv[2]); } sum(num1,num2) int num1,num2; { return num1+num2; }
void main() { int i=i++,j=j++,k=k++; printf(“%d%d%d”,i,j,k); }
Is the following statement a declaration/definition. Find what does it mean? int (*x)[10];
{ int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }
void main() { int x,y=2,z; z=(z*=2)+(x=y=z); printf("%d",z); }
Write a program to receive an integer and find its octal equivalent?
main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
what is variable length argument list?
Is there any difference between the two declarations, 1. int foo(int *arr[]) and 2. int foo(int *arr[2])
Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable, but aac or bcd are unacceptable.