The book that i am currently reading states that when you declare a function in c that accepts no arguments, but you do not use the keyword void "the function call can pass any arguments it wants". so i attempted this.
int number();
int main(void)
{
int x =1;
printf("%d",number(x));
}
int number()
{
return x;
}
but it did not compile??? how does this work?
This is an obsolescent feature1 from before C was standardized, decades ago.
Never use it.
In ancient C, a decade before you were born, you could declare a function with no parameters. When you called it, the compiler would promote the arguments to default types and pass them to the function. Essentially, the compiler figured out the parameter declarations from the arguments in the call.
The function should still be defined with parameters, and they should match the way the function is called.
1 “Feature” is the wrong word. It was the way things were done at the time, since better ways were not yet widely developed. In a new programming language, this characteristic would be considered a deficiency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With