C++ Program for Default Arguments in Function

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

// Default arguament in function
#include<iostream>
#define clrscr() system("cls")
using namespace std;
int add(int a,int b=100,int c);
int main()
{
    clrscr();
    int result;
    // Three Argument
    result=add(10,10,10);  
    cout<<"\nAddition is"<<result;
   // Two Arguement
   result=add(10,10);  
    cout<<"\nAddition is"<<result;
  //One Argument
    result=add(10);  
    cout<<"\nAddition is"<<result;
//Without Argument
    result=add();  
    cout<<"\nAddition is"<<result;
  return 0;
}
int add(int a ,int b ,int c)
{
    int x;
    x=a+b+c;
    return x;
}

Program 2

// Default arguament in function
#include<iostream>
#define clrscr() system("cls")
using namespace std;
float area(float r,float PI=3.14);
int main()
{
    clrscr();
    float A;
    A=area(12.3,3.142);
    cout<<"\n Area is : "<<A;
   return 0;
}
float area(float r,float PI)
{
    float A;
    A=PI*r*r;
    return A;
}

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *