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 |
enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); }
Cluster head selection in Wireless Sensor Network using C programming language.
#define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }
4 Answers Google, HCL, Quick Heal, WTF,
Write, efficient code for extracting unique elements from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9).
13 Answers Intel, Microsoft, TCS,
#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above
#include<stdio.h> int main() { int x=2,y; y=++x*x++*++x; printf("%d",y); } Output for this program is 64. can you explain how this output is come??
Find the largest number in a binary tree
#define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); }
What is the output for the following program main() { int arr2D[3][3]; printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ); }
void main() { int x,y=2,z; z=(z*=2)+(x=y=z); printf("%d",z); }
int i,j; for(i=0;i<=10;i++) { j+=5; assert(i<5); }
char inputString[100] = {0}; To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString, sizeof(inputString), fp)