Default Value Function In C++

 Default Value Function In C++

Default Value Function - Function which parameters have some default value.

#include <iostream>
using namespace std;

void locality(int age = 18) // Passing A Default Value Of age
{
    cout<<"Your Age Is: "<<age<<endl;
}

int main()
{
    locality(); //Calling Without Passing Argument 
    locality(23); //Calling By Passing Argument 
    return 0;
}


Output - 
Your Age Is: 18
Your Age Is: 23

Comments

Popular posts from this blog

Array Of Objects In C++ | Array Of Objects Explained With Real Life Example

Pointers In C++ | Pointer Explained With Real Life Examples | Pointers In OOPs C++

Destructor In C++ | Destructor Explained With Real Life Examples