A function is a self-contained block of statements that perform a specific task. A function can be call many times.By using function we can divide a code into the function.Function provides modularity and code reusability.
There are two types of functions-
» Library Functions
» User-defined functions
Library Functions
They Are Pre Defined header files such as ceil(), cos(), exp(), etc.
User-defined functions
These functions are declared by the user depends on their requirements.It reduces complexity of a big program.
function-name(parameters) { statement; }
(1) Without return - Without argument
void main(void) { statement; }
(2) Without return - With argument
void main(int a) { statement; }
(3) With return - Without argument
int main() { statement; return(); }
(4) With return - With argument
int main(int a,int b,....) { statement; return(a,b,...); }
#include void welcome() { cout<<"Hello World"; } void main() { welcome(); //calling a function welcome(); //calling a function second time }
Output:
Hello World
Hello World