c++functionprototyping

Prototyping in C++


If I prototype a function above the main function in my code, do I have to include all parameters which have to be given? Is there a way how I can just prototype only the function, to save time, space and memory?

Here is the code where I came up with this question:

#include <iostream>

using namespace std;

int allesinsekunden(int, int, int);

int main(){
    int stunden, minuten, sekunden;

    cout << "Stunden? \n";
    cin >> stunden;
    cout << "Minuten? \n";
    cin >> minuten;
    cout << "Sekunden= \n";
    cin >> sekunden;

    cout << "Alles in Sekunden= " << allesinsekunden(stunden, minuten, sekunden) << endl;
}

int allesinsekunden (int h, int m, int s) {
    int sec;

    sec=h*3600 + m*60 + s;

    return sec;

}

Solution

  • "If I prototype a function above the main function in my code, do I have to include all parameters which have to be given?"

    Yes, otherwise the compiler doesn't know how your function is allowed to be called.
    Functions can be overloaded in c++, which means functions with the same name may have different number and type of parameters. Such the name alone isn't distinct enough.

    "Is there a way how I can just prototype only the function, to save time, space and memory?"

    No. Why do you think it would save any memory?