If I m declaring function after a main body it's showing error.But If I m declaring it before main it's working.wats the concept | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

If I m declaring function after a main body it's showing error.But If I m declaring it before main it's working.wats the concept

https://code.sololearn.com/cjZYDOOGKvkp/?ref=app

24th Mar 2018, 6:52 PM
Deepak Bhalode
Deepak Bhalode - avatar
7 Answers
+ 4
In order to call a function, the compiler must know the prototype of it. If you wish to have your function follow main, declare the prototype before main and it will work. Putting this before main, allows the definition to be after: int print();
24th Mar 2018, 7:21 PM
John Wells
John Wells - avatar
+ 2
main is a function where the program execution starts. Every program has a main function.
24th Mar 2018, 6:59 PM
Nilesh
Nilesh - avatar
+ 2
You cannot use a function or variable which is not yet declared. eg: x = 3; // x not yet declared int x; This is wrong. Because the compiler doesn't know what x is and you are using it.🤐 Correct way: int x;. // first declare x x = 3; Likewise: int print();. // first declare the function int main(){ print(); } int print(){ cout<<"You got it?"; }
24th Mar 2018, 7:17 PM
Nilesh
Nilesh - avatar
+ 2
no problem bro
24th Mar 2018, 7:20 PM
Nilesh
Nilesh - avatar
+ 1
ty sir
24th Mar 2018, 7:20 PM
Deepak Bhalode
Deepak Bhalode - avatar
+ 1
I got it...concept clear ...ty sir
24th Mar 2018, 7:22 PM
Deepak Bhalode
Deepak Bhalode - avatar
0
ys it is...sir bt wats the concept y is it necessary to declare dt function before main function then after only we cn call it in main body . y it's nt working if I will declare dt function in the main body?
24th Mar 2018, 7:01 PM
Deepak Bhalode
Deepak Bhalode - avatar