M
PRO
Manfred
asked

Expert
Abhay Jajodia answered
Hi Manfred,
Yes, you can define a function after main(). The only difference is that if main() calls that function, you should write a function prototype above main() so the compiler knows the function exists.
Example:
int findSquare(int n); // prototype
int main() {
printf("%d", findSquare(5));
return 0;
}
int findSquare(int n) { // definition after main
return n * n;
}
If the function is defined before main(), you usually do not need the prototype.
If you have more questions, I am here to help 😊
C
This question was asked as part of the Learn C Programming course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer