Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function Declaration/Function Definition

Tags:

c++

function

Does it matter if the function definition is before the int (main) or after the int main?

I've seen it both ways and am trying to find the proper way to display the function definition and declaration.

like image 635
Zud Avatar asked May 30 '26 02:05

Zud


2 Answers

No .. it doesn't. Its a matter of preference. Choose which you prefer and be consistent!

like image 181
Goz Avatar answered Jun 01 '26 15:06

Goz


The function definition (which contains the actual code) can be anywhere, even in a different file, as long as the declaration (the function prototype) appears before you call the function.

like image 30
casablanca Avatar answered Jun 01 '26 16:06

casablanca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!