In a C program, where do you define a function? Why?
I suppose that the function definition is generally written outside the main function and after the function declaration. It's correct? Why?
Thank you all!
You have to define a function outside main()
, because main()
is a function itself and nested functions are not supported in C.
Declaring a function is in modern C not necessary, because a function definition implies a function declaration. There are still two reasons to do it:
A function declaration can be exported in a header file and then used by other translation units that import the header file.
C is usually translated one-pass that means that you cannot use a function before it is declared without warning. If you have a function a()
calling a function b()
and vice versa, you cannot define both functions before declaring at least one.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments