05 Functions
05 Functions
05 Functions
Contents
o Predefined functions
o User-defined functions
o Scope rules
o Parameters
o Function overloading
o Default arguments
o Types:
• Pre-defined functions
• User-defined (Programmer-defined) functions
o Syntax:
return expression;
o Example:
int Factorial(int N)
{
if (N == 0)
return 1;
return N * Factorial(N-1);
}
o Examples:
static int a;
static float b;
o Example:
void getInput(double& N);
void sum(int N, int& s);
o Version 01:
void swap(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
o Version 02:
void swap(int& a, int& b)
{
int temp;
temp = a;
a = b;
b = temp;
}
o Examples:
int test();
void test(int);
void test(float);
int test(float);
float test();