Thursday, May 21, 2020

Default Parameters using functions in C++


  • Program :

#include <iostream>
#include <string>
using namespace std;
void myFunction(string country = "Norway") {
  cout << country << "\n";
}

int main(){
  cout <<"\n----------------FUNCTION PARAMETERS----------------\n";
  cout <<"\n----------------Default Parameters----------------\n";
  myFunction("Sweden");
  myFunction("India");
  myFunction();
  myFunction("USA");
  return 0;
}

  • Output :

No comments:

Post a Comment

Function Overloading in C++

https://monitechvenkat1620.blogspot.com Program : #include <iostream> using namespace std; int c(int x, int y) {   return...