Make Parameters Option in Function

In this tutorial I will explain how to keep parameters of a function optional

This tutorial explains:

1. What is an Default Argument?
2. How to make parameters optional
3. Assign a value to a parameter

Video tutorial: http://www.youtube.com/watch?v=uCtIvgo-sH8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream.h>
#include<conio.h>

int add(int a, int b=0)
{
    return a +b;
}
main()
{
    int x=10, y=20, sum;/* Notice that we have passed only one parameter rather than two*/

    sum=add(x);/*It would normally give you an error, but one of the parameters is optional now*/
    cout<<sum;
}


Topic archived. No new replies allowed.