1#include <iostream>
2using namespace std;
3//REMOVE COMMENTS TO USE VARIOUS FUNCTION CALLING METHODS
4// function declaration
5void swaper(int &,int&) ;// call by reference
6//void swaper(int *,int * );// call by address
7//void swaper(int,int );//call by value
8
9
10int main () {
11 // local variable declaration:
12 int a = 100;
13 int b = 200;
14 /* calling a function to swap the values using variable reference.*/
15 swaper(a, b);// call by reference
16 //swaper(&a, &b); //call by address
17 //swaper(a, b); // call by value
18 cout << "After swap, value of a :" << a << endl;
19 cout << "After swap, value of b :" << b << endl;
20
21 return 0;
22}
23
24//CALL BY refernce DEFINATION
25void swaper(int &x, int &y) // x and y are ref variable..ie they are other name for a and b
26{
27 int temp;
28 temp = x; //save the value as x which is ref for a
29 x = y; // put y into x
30 y = temp; // put x into y
31}
32//CALL BY ADD DEFINATION
33/*void swaper(int *x, int *y) {
34 int temp;
35 temp = *x; //save the value at address x
36 *x = *y; // put y into x
37 *y = temp; // put x into y
38*/
39
40// CALL BY VALUE DEFINATION
41/* void swaper(int x, int y) {
42 int temp;
43 temp = x; // save the value of local x
44 x = y; // put local y into local x
45 y = temp; //put local x into local y
46*/
47
48
49
1// function example
2#include <iostream>
3using namespace std;
4
5int addition (int a, int b)
6{
7 int r;
8 r=a+b;
9 return r;
10}
1#include <iostream>
2#include <stdlib.h>
3#include <iomanip>
4#include <fstream>
5using namespace std;
6
7void function_one(double, double, double);
8
9int main() {
10 double r1 = 1.0;
11 double r2 = 2.0;
12 double x = 0.0;
13 function_one(r1, r2, x);
14 return 0;
15}
16
17void function_one(double rmin, double rmax, double x0) {
18 cout << "Function got called" << endl;
19}