Passing Parameter

Parameter is the variable listed inside the parentheses in the method definition. An argument is the actual value that is sent to the function when it is called. We can create a method with n number of Parameters inside. when a method is called, a new storage location is created for each parameters.

CODE

EG 1 . Creating a multiplication table method with table number and limit as Parameters.

#include <iostream>
using namespace std;

void MultiplicationTable(int tableNumber, int limit);

int main() {
    MultiplicationTable(17,20);
}

//Here table number and limit are the Parameters. Whenever this method invoked those 2 parameters value must be assigned.
void MultiplicationTable(int tableNumber, int limit) {
    for (int i=1; i <= limit; i++) {
        cout << tableNumber << " * " << i << " = " << tableNumber*i << endl;
    }
}



EG 2 . Creating a method to print Right angle triangle shape using * and passing row value as parameter.

#include <iostream>
using namespace std;

void PrintRightAngleTraingleShape(int row);

int main() {
    PrintRightAngleTraingleShape(10);
}
void PrintRightAngleTraingleShape(int row) {
    for (int i=1;i<=row;i++) {
        for (int j=1;j<=i;j++) {
        cout << "*";
        }
    cout << endl;
    }
}




(Click Here, For more exercises)