+ 6

Hello, could you tell me the difference between the function declared outside main() and inside main()? Thanks in advance! 🙌🏻✨

For example: int square(int side); int main() { // Code } int square(int side){} ****Versus**** int main() { int square(int side); // Code } int square(int side){}

22nd Jan 2021, 2:06 PM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar
9 Réponses
+ 8
Read the code and it's comment to see the difference. https://code.sololearn.com/cjF9pRzhOkgX/?ref=app
22nd Jan 2021, 2:19 PM
minirkk
minirkk - avatar
+ 9
XXX Thank you so much! Got the point! 😄
22nd Jan 2021, 2:52 PM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar
+ 7
A function declared outside the main() function can be accessed outside the main() function. https://code.sololearn.com/c9GwHJvW4q71/?ref=app Whereas a function declared inside the main() function can *only* be used inside the main() function https://code.sololearn.com/c43c85O5Lr0G/?ref=app
22nd Jan 2021, 2:19 PM
XXX
XXX - avatar
+ 6
Thanks RKK 🙌🏻 Got it!
22nd Jan 2021, 2:51 PM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar
+ 4
Martin Taylor I didn't understand why RKK ' s code is not an example of local function declaration.
23rd Jan 2021, 8:01 PM
Sonic
Sonic - avatar
+ 3
You're welcome Mahima Rajvir Singh :)
22nd Jan 2021, 2:53 PM
minirkk
minirkk - avatar