Can you declare functions after the main () or it should be only be declared before main() so that it can be invoked | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can you declare functions after the main () or it should be only be declared before main() so that it can be invoked

3rd Jun 2019, 12:24 PM
Kapil xtio
Kapil xtio - avatar
2 Answers
+ 4
You seem to be asking about C++. If you define them in one run, you have to define them before they are used: above main. int f(int n) {//whatever code} int main() {... In C(++), you have the possibility to separate the declaration from the definition. If you do this, you can put only the declararion on top, and the definition can follow after main. int f(int); int main() {...} int f(int n) {//And now the actual definition}
3rd Jun 2019, 12:33 PM
HonFu
HonFu - avatar
0
You can declare functions everywhere. At least at Java and C#
3rd Jun 2019, 12:25 PM
DolphieDude
DolphieDude - avatar