The function declaration here is called the forward declaration
. This is used if the function has been called [used] before it is defined.
In your code, see, when navin()
is called inside main()
, at that point, the function is not yet defined. By using the forward declaration, you're telling compiler,
"This is the function signature. This function definition is present later in the code, continue the compilation."
Without this forward declaration, most of the c
compilers will show you a warning [termed as implicit declaration
] that they are not able to find the function navin()
, so, the compiler will assume the function prototype as
- any number of input arguments
- return type as integer.
In most of the cases, this ends up in a disaster.
You can find more information in this related question.
Profound usage: The header files.
NOTE:
In older c
standards, c89
, this was supposed to be only an warning, but the newer versions, c99
and c11
defines this [missing forward declaration] to be an error. However, by default gcc
[c complier on linux] doesn't implement these standards. If you tell gcc
explicitly to follow c99
and higher, it'll produce the correct error message.