I guess I don't fully understand the way functions in C work.
For instance, I'll use this program as an example:
So now, what I don't understand is, the data types. We declare the parameter fahr to be of the int data type. But now, what if I were to (say for instance, in the main function) put a variable as an argument for the celsius function, I don't understand how it works when say for instance, I were to declare this variable as another data type than what fahr is.
Also, I don't understand the return statement, what if I return a variable of type int, but the function is of another data type? hm.
Also, the data types are switched up in this program for a reason. :P
For instance, I'll use this program as an example:
Code:
#include <stdio.h>
float celsius(int);
main()
{
int a;
for(a = 0; a <= 300; ++a)
celsius(a);
return 0;
}
float celsius(int fahr)
{
int a, b;
a = (5.0 / 9.0) * (fahr - 32.0);
b = printf("%d\n", a);
return b;
}
Also, I don't understand the return statement, what if I return a variable of type int, but the function is of another data type? hm.
Also, the data types are switched up in this program for a reason. :P
Comment