Passing Arguments to Function in C++

Passing arguments to Function in C++ programming. Functions are used to divide a large program into sub-programs for easy control. All these sub-programs are called sub-functions of the program.

Program Passing Arguments to Parameters

Program

#include<iostream.h>
#include<conio.h>
void fun(int, int); //defining function with parameter.
void fun2(int, int, char); //defining function with parameter.
void main()
{
int a = 5;
int b = 65;
char c = 'C';
fun(a, b); //calling and passing argument to parameter.
fun2(a, b, c); //calling and passing argument to parameter.
getch();
}
void fun(int i, int j) //passing argument here to parameter.
{
int l = i; //assigning passed
int m = j; //values to variables.
cout<<"The Passed a value is: "<<l<<endl;
cout<<"The Passed b value is: "<<m<<endl;
}
void fun2(int x, int y, char z) //passing argument here to parameter.
{
int e = x; //assigning passed
int f = y; //values to variables.
char g = z;
cout<<"The Passed a value is: "<<e<<endl;
cout<<"The Passed b value is: "<<f<<endl;
cout<<"The passed c value is: "<<g<<endl;
}
Output
The Passed a value is: 5
The Passed b value is: 65
The Passed a value is: 5
The Passed b value is: 65
The passed c value is: C

Program Passing Arguments to Parameters Another Method

Program

#include<iostream.h>
#include<conio.h>
void fun(int, int); //defining function with parameter.
void fun2(int, int, char); //defining function with parameter.
void main()
{
int a = 5;
int b = 65;
char c = 'C';
fun(a, b); //calling and passing argument to parameter.
fun2(a, b, c); //calling and passing argument to parameter.
getch();
}
void fun(int i, int j) //passing argument here to parameter.
{                 //printing passed values.
cout<<"The Passed a value is: "<<i<<endl;
cout<<"The Passed b value is: "<<j<<endl;
}
void fun2(int x, int y, char z) //passing argument here to parameter.
{                 //printing passed values.
cout<<"The Passed a value is: "<<x<<endl;
cout<<"The Passed b value is: "<<y<<endl;
cout<<"The passed c value is: "<<z<<endl;
}
Output
The Passed a value is: 5
The Passed b value is: 65
The Passed a value is: 5
The Passed b value is: 65
The passed c value is: C