This situation occurs due to not using function prototypes. If you do, you will get an error and the build will fail.
As it is, func() produces a warning that it is not defined and is assumed an extern returning an int. The linker sees func() as an unresolved function and it has func(int) available. In C, func() just means a "function named func with unspcified arguments". So it links a call to func(int). Later it links func(6) to
func(int) and off you go.
This situation was fixed in C++ by implementing function overloading. since func() in C++ is a function with no arguments and func(int) is a different function with one argument.
I suggest in C that a) never accept a build as OK if it has any warnings and b) always use function prototypes.