Firstly, there's no requirement in C language to provide a prototype for a function before it is called. In C99 version of the language there's a requirement to declare a function before it is called, but still there's no requirement to provide a prototype.
Since your compiler did not complain, you must be using a C89/90 compiler, not a C99 compiler.
Secondly, in C89/90, when you call an undeclared function wile passing arguments of type float
and char
as you do in
printit(a,ch);
the compiler will perform default argument promotions and actually pass values of type double
and int
. Your function must be defined accordingly for the code to work. You defined your function as
printit(a, ch)
{
...
That definition means that both parameters have type int
. This violates the above requirement. The behavior of your code is undefined. It no longer makes any sense to analyze the code any further or guess why it prints something the way it prints it. The behavior of your code is, once again, undefined.
The proper definition for your (undeclared) function might look as follows
int printit(double a, int ch)
{
...
Alternatively, it can be defined in K&R style as
printit(a, ch)
float a;
{
...
That would probably make your code to work correctly. However, the much better approach would be to provide a prototype for printit
before calling it. Which prototype you want to use - void printit(double a, int ch)
or void printit(float a, char ch)
or something else - is for you to decide.