• Sat. Feb 4th, 2023

SoftwareMile.com

Latest Software News and Hacks

Variadic functions

Byadmin

Jul 31, 2022

Hey guys,
i just humbled across variadic functions but i just don´t understand them can someone explain it for me in simple thermes?

#include <stdarg.h> #include <stdio.h> double average(int count, ...) { va_list ap; int j; double sum = 0; va_start(ap, count); /* Requires the last fixed parameter (to get the address) */ for (j = 0; j < count; j++) { sum += va_arg(ap, int); /* Increments ap to the next argument. */ } va_end(ap); return sum / count; } int main(int argc, char const *argv[]) { printf("%fn", average(3, 1, 2, 3)); return 0; } 

submitted by /u/Leonjustme
[link] [comments]


Go to Source of this post
Author Of this post: /u/Leonjustme
Title Of post: Variadic functions
Author Link: {authorlink}