FUNCTION PARAMETER IN C++

Maha

FUNCTION PARAMETER IN C++

          In C++, Parameters are a special kind of variable in C++ that are only used when a function is declared. The parameter can only be used in the function for which it was supplied. Each parameter that is declared in a list of parameters must be assigned a data type.

         A function parameter in C++ is a variable that is set when a function is created. These variables either take or receive arguments when a function is called. The value that is supplied to a function upon its call in C++ is known as an argument.

They are 2 types of function parameters:

     * Mandatory  parameter

     * Optional Parameter


Syntax:

void functionName(parameter1, parameter2, parameter3) 

{

  // code to be executed

}


Example:

#include <iostream>

#include <string>

using namespace std;

void myFunction(string fname)

{

  cout << fname << "\n";

}

int main()

{

  myFunction("Leo");

  myFunction("Jessy");

  myFunction("leeza");

  return 0;

}

Output:

Leo

Jessy

Leeza





Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send