Tuesday, 15 January 2013

create a function with variable pointers parameters in C -



create a function with variable pointers parameters in C -

how create function variable pointers parameters take number of pointer , print such :

print("hello ","world "); print("i'm ","adil"," blah "," blah");

result :

$ ./myprogramme hello word im adil blah blah

i found stdarg.h don't know how create ?

in c, can create variadic function using stdarg.h. illustration wikipedia link,

#include <stdarg.h> double average(int count, ...) { va_list ap; int j; double sum = 0; va_start(ap, count); /* requires lastly fixed parameter (to address) */ (j = 0; j < count; j++) { sum += va_arg(ap, double); /* increments ap next argument. */ } va_end(ap); homecoming sum / count; }

c

No comments:

Post a Comment