In general, when using Variadic functions, we always give some sort for number of expected inputs, but never know how many are passed.
Then, how does compiler able to detect when I passed more arguments than required to printf()
function ?.
Below is the sample code
#include <stdio.h>
int main()
{
printf("Hello World", 2);
return 0;
}
Output:
main.c: In function ‘main’:
main.c:6:12: warning: too many arguments for format [-Wformat-extra-args]
6 | printf("Hello World", 2,3,4);
| ^~~~~~~~~~~~~
Hello World
I was using the following online compiler : https://www.onlinegdb.com/online_c_compiler