Object Oriented Concepts and Programming

Blog is for Object oriented concepts and prgramming. Specially for MCA GTU (Gujarat Technological University) student

RSS
  • Home
  • Edit

How To Implement Default Argument in Function.

Thursday, April 8, 2010 by Vishal Joshipura | 1 comments
/*
This code shows how to use default argument in function
or how to create an optional parameter to the function

*/

#include

void div(int a,int b=1)
{
    float c;
    cout<<<"A is "<
    cout<<<"B is "<
    c= float(a)/b;
    cout<<<"A / B is "<
}


int main(void)
{
    int i=10,j=2;
    cout<<<"Default Argument";
    div(i,j);
    div(i);
    return 0;
}

/* Here Second parameter of div() function is
optional we can ommit it autometically consider
as Default argument value as 1*/

Defualt Argument

1 comment:

Dr. Parag Shukla said...

Very good start dear........

Keep ahead...

April 8, 2010 at 7:09 PM

Post a Comment

Subscribe to: Post Comments (Atom)

Blog Archive

  • ▼  2010 (10)
    • ►  November (1)
    • ►  August (3)
    • ►  May (2)
    • ▼  April (3)
      • Program code for calculating Factorial of a no, Ho...
      • Startup code for C/C++, How actual program execuio...
      • How To Implement Default Argument in Function.
    • ►  March (1)

Followers

Labels

  • Argument (1)
  • Class (1)
  • Defualt Argument (1)
  • Fact (1)
  • Factorial (1)
  • Item (1)
  • OOCP Material (1)
  • Pass by address (1)
  • Pass By argument (1)
  • Recursive Function (1)

Contributors

  • Dr. Parag Shukla
  • Vishal Joshipura
  • vaibhav

Pages

  • Home
Copyright © 2010 Object Oriented Concepts and Programming