Functions: A Little Question.

Hello guys. I just wanted to know the difference between declaring a function this way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <cstdlib>
#include <iostream>

using namespace std;

type Function (type_1 Par_1, type_2 Par_2, ..., type_n Par_n); 

int main(int argc, char *argv[])
{
    *** CODE ***
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

type Function (type_1 Par_1, type_2 Par_2, ..., type_n Par_n)
{
    *** CODE ***
}


with this one:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <cstdlib>
#include <iostream>

using namespace std;

type Function (type_1 Par_1, type_2 Par_2, ..., type_n Par_n)
{
    *** CODE ***
}

int main(int argc, char *argv[])
{
    *** CODE ***
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


Thank you for your answers!
I don't know the actual term but it goes something like forward-declare function. For small program like yours you don't find a difference but if you have a lot of files and you intend to let other code call your function, it will be useful. You can put those function declaration in a .h file so other code will know what parameters to call your function. Then the actual function definition or implementation could be in some other .cpp etc files. That is, there is a segregation of interface and implementation thing here.
Thanks you @sohguanh
I also agree with your answer
Topic archived. No new replies allowed.