Variable Length arguments ... Just because you don't see something doesn't mean it isn't there

I use to program in C and C++. Before this incident I was fully convinced with the fact that functions receive fixed number of arguments. I never OBSERVED the behavior of functions like printf ( ), sum ( ), min ( ), etc. we taught in our courses that these functions are differ than user defined functions because they are built-in functions. Yes, It's true but few things are still need to be discovered until I came across this ... I was reading JAVA docs and I came across this ...

 

 I think does C or C++ have also have this feature? After doing couple of clicking on Internet ... I came across this

 

 

I dig dive into it... and play it with more
 
Such type of functions are called "Variadic functions" which take a  variable number of argument.
* To declare a variadic function, an ellipsis appears after the list of parameters.
* E.g. int printf(const char* format...);, which may be preceded by an optional comma. 
 
 

 

 |_ i |\| K $:

* https://www.linkedin.com/pulse/modern-c-variadic-functions-how-shoot-yourself-foot-avoid-zinin
* https://eli.thegreenplace.net/2014/variadic-templates-in-c/
* https://en.cppreference.com/w/cpp/utility/variadic
* https://docs.microsoft.com/en-us/cpp/cpp/functions-with-variable-argument-lists-cpp?view=msvc-160
* https://stackoverflow.com/questions/766559/when-do-you-use-varargs-in-java


In this blog I just post some surface based material, might be in some another blog I talk about question like How stack is maintained for such functions? and many more... 

Comments