arguments and parameters in c code example
Example 1: command line arguments in c
int main( int argc, char *argv[] )
./a.out kiran kumar gun
./a.out is arg[0]
kirna is arg[1]
Example 2: variable parameters in c
#include <stdio.h>
#include <stdarg.h>
double average(int num,...) {
va_list valist;
double sum = 0.0;
int i;
va_start(valist, num);
for (i = 0; i < num; i++) {
sum += va_arg(valist, int);
}
va_end(valist);
return sum/num;
}
int main() {
printf("Average of 2, 3, 4, 5 = %f\n", average(4, 2,3,4,5));
printf("Average of 5, 10, 15 = %f\n", average(3, 5,10,15));
}