In c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

In c++

if the function is implented in the same file .. why do I see programmers write it's definition at the top of the same file ?

9th Aug 2018, 5:30 PM
Ahmed Mamdouh
Ahmed Mamdouh - avatar
2 Answers
+ 2
int add(int a, int b); // some codes here .... int add(int a, int b) { // function body } Were you referring to something like that? the first one is a declaration only, it is created so that its implementation can be invoked by other functions declared above the implementation, without that, the 'add' function will have to be declared before its callers before it can be used. Hth, cmiiw
9th Aug 2018, 7:02 PM
Ipang
+ 2
really.. I thought order doesn't matter here .. thanx
9th Aug 2018, 7:25 PM
Ahmed Mamdouh
Ahmed Mamdouh - avatar