Wednesday, 11 February 2015

c++ program for function with default arguments

C++ program for function with default arguments

#include <iostream>
using namespace std;

void display(char = '*', int = 1);

int main() {
    cout<<"No argument passed:\n";
    display();
    
    cout<<"\n\nFirst argument passed:\n";
    display('#');
    
    cout<<"\n\nBoth argument passed:\n";
    display('$', 5);

    return 0;
}

void display(char c, int n){
    for(int i = 1; i <=n; ++i) {
        cout<<c;
    }
    cout<<endl;
}

No comments:

Post a Comment