How we can use the functions in C++

Member Avatar for ArashVenus

If you mean how can you divide a program into functions and use the functions ,
there are 2 ways you can do It ,
1-writing the functions before main ,
2-writing them after main , and predeclaring them above main .

first one is simple , you write functions above main like this :

type function1 (inputs)
{
    statements and code;
}

type function2 (inputs)
{
    statements and code;
}

...

int main ()
{
    function1(inputs);
    function2(inputs);
    ...
    return 0;
}

second one is written like this :

type function1 (inputs);
type function2 (inputs);
...
int main 
{
    function1(inputs);
    function2(inputs);
    ...
    return 0;
}


type function1 (inputs)
{
    statements and code;
}

type function2 (inputs)
{
    statements and code;
}

...

ps : I prefer the first one .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.