Default Argument
Default Argument C++ provides to define default argument value for functions In function def the default values are given Whenever a call is made to a function without specifying an argument, then the prog will automatically assign values to the parameters from the default arguments specified in fun def eg Void function(int a, int b, int c=100) {.. } when we calling the fun with 2 arguments then value of c will be 100 function(1,2)// missing arg Here value of a 1 b 2 and c100 (default value)
Default Argument If the above function is called as Function(1,2,3);// no missing arg Then values of a1, b2 and c3 In default argument we can assign default values from right arg to left arg Cannot provide default value to a particulate argument in the middle Ie Function(int a,int b,int c=100)valid Function (int a,int b=200,int c=100) valid Function(int a,int b=200,int c)invalid
Default Argument Questions Addition of two nos, three nos and four nos