SlideShare a Scribd company logo
1 of 7
AmritKaur Functions in C++
1
Chapter 5: Functions
A function is a named, independent section of C++ code that performs a specific task and
optionally returns a value to the calling program.
A function is a part of program called by another part of a program. In a program, there are
many calling function (caller) and called functions (callee).
5.1 Function Definition
Function Definition is the actual function body, which contains the code that will be
executed. Function definition must not end with semicolon. A function can be
defined as follows
Syntax:
returntype functionname (parameter(s))
{
//function body
}
Example 1: function definition to find average of 5 nos
float average(int a, int b,int c, int d, int e )
{
float avg;
avg=(a+b+c+d+e)/5.0f;
return (avg)
}
Here floatspecifiesreturntype; average is name of function; int a, int b, int c, int d , int e are
parameters
Example 2: function definition and function call
#include<iostream.h>
void func()
{
cout<<” IN FUNCTION func()”<<endl;
}
void main()
{
cout<<”IN FUNCTION main()”<<endl;
func();//call to a function
cout<<” BACK IN main() FUNCTION”<<endl;
}
AmritKaur Functions in C++
2
5.2 Function Prototype
A function must be defined before using it. That is, if the function definition does not
precedes the function call, the function need to declare. The process of declaring
function is known as function prototyping.
In other words, if programmer wants to define a function after using it they have to
declare the function at the top just after pre-processor directives. It includes
returntype , function name and paramterlist followed by semicolon.
Syntax: returntype functionname (paramtere(s));
Example 3 : float average(int a, int b,int c, int d, int e ) ;
5.3. Types of Function
In C++, the function are classified into types
Library Functions:
Library functions are pre defined and pre compiled functions present in a library file
and found in include directory with extension .h
Example 4:
a. sqrt(), pow() are available in header file math.h
b. strlen(), strcpy() are present in string.h
User defined function
It is small independent program designed by user for performing the specific
operations.
5.4 Elements of User defined Function
Return Types
Functions can return a value to the caller. When a called function sends the data
back to calling program it is known as return type. If the function doesn’t return a
value use void. Otherwise it can return one value by using the return keyword. The
value to be returned must match with the value of return type.
AmritKaur Functions in C++
3
Function Name
It is name of the function that is used while calling. It can be any valid identifier.
Parameters or Arguments
Passing a values during function call takes place through arguments. The argument(s)
or parameter(s) of a function is/are the data the function must receive when called
from another function. When a calling function sends the data to a called function,
data is known as parameters or arguments. Types of Arguments
 Actual Parameters / Arguments : Arguments listed in function calling statement.
These are the values passed to function to compute.
 Formal Parameters / Arguments : The arguments used in the function
declaration. They receive the values supplied by calling program.
 Default Parameters / Arguments : When a default value is assigned to formal
arguments it is known as default arguments. Useful in case when argument is
not passed in call statement
Example 5: Program to find average of 5 nos
#include<iostream.h>
#include<conio.h>
float average (int a, int b, int c, int d, int e) // formal parameters
{
float avg;
avg=(a+b+c+d+e)/5.0;
return avg;
}
void main()
{ int a,b,c,d,e;
cout<<"Enter Five Numbers";
cin>>a>>b>>c>>d>>e;
float result=average(a,b,c,d,e); // actual parameters
cout<<"Avergare of "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" = "<<result;
}
5.5 Invoking Function
In C++, function can be invoked or called in one of the following ways
a. Call By Value
AmritKaur Functions in C++
4
b. Call By Reference
5.5.1 Call By Value
 In Call by Value, the value of a parameter(s) is passed.
 When parameters are passed by value, the called function creates the new variables
of same type and copies the argument values into it.
 In call by value, the value of actual (original) parameter remain unchanged.
Example: Program to swap (interchange) two numbers using call by value.
#include<iostream.h>
#include<conio.h>
void swap(int p, int q) // p and q are formal arguments
{ // p is the copy of a and q is copy of b
int temp;
cout<<"nValue of p and q...... BEFORE swapping";
cout<<"np="<<p<<" t q="<<q;
temp=p;
p=q;
q=temp;
cout<<"nValue of p and q...... AFTER swapping";
cout<<"np="<<p<<" t q="<<q;
}
void main()
{
int a,b;
clrscr();
cout<<"n Enter value of a:";
cin>>a;
cout<<"n Enter value of b:";
cin>>b;
cout<<"nValue of a and b IN main ()";
cout<<"na="<<a<<" t b="<<b;
//call to swap function - call by value
swap(a,b);//a and b are actual parameter, their value is passed
cout<<"nValue of a and b IN main () after swap";
cout<<"na="<<a<<" t b="<<b;
}
5 10
A B
0x12 0x70
5 10
A B
0x12 0x70
AmritKaur Functions in C++
5
5.5.2 Call By Reference using an Alias
 A reference provides an alias (alternate names) for the variable.
 In call be reference using alias, a reference of the parameter in the calling program is
passed.
 While passing, call by reference, the value of actual (original) variable changes
because there is only one copy of data is maintained with two different names.
Example: Program to swap (interchange) two numbers using call by reference using
alias.
#include<iostream.h>
#include<conio.h>
void swap(int &p, int &q)// p and q are formal arguments
{ // ampersand indicates p is alias of a
// and q is alias of b
int temp;
cout<<"nValue of p and q...... BEFORE swapping";
cout<<"np="<<p<<" t q="<<q;
temp=p;
p=q;
q=temp;
cout<<"nValue of p and q...... AFTER swapping";
cout<<"np="<<p<<" t q="<<q;
}
void main()
{
int a,b;
clrscr();
cout<<"n Enter value of a:";
cin>>a;
AmritKaur Functions in C++
6
cout<<"n Enter value of b:";
cin>>b;
cout<<"nValue of a and b IN main ()";
cout<<"na="<<a<<" t b="<<b;
//call to swap function - call by reference using alias
swap(a,b);//a and b are actual parameter, their value is passed
cout<<"nValue of a and b IN main () after swap";
cout<<"na="<<a<<" t b="<<b;
}
5.5.3 Call By Reference using an Pointers
 In call be reference using pointers, an address of actual (original) parameter is
passed to the calling program.
 While passing, call by reference, the value of actual (original) variable changes
because there is only one copy of data is maintained.
Example: Program to swap (interchange) two numbers using call by reference using
pointers.
#include<iostream.h>
#include<conio.h>
void swap(int *p, int *q)// p and q are formal arguments
{ // p contain address of a
// q contain address of b
int temp;
cout<<"nValue of p and q...... BEFORE swapping";
cout<<"np="<<*p<<" t q="<<*q;
temp=*p;
*p=*q;
*q=temp;
cout<<"nValue of p and q...... AFTER swapping";
cout<<"np="<<*p<<" t q="<<*q;
}
void main()
{
int a,b;
Afterswap() functionexecuted
10 5
P Q
A B
AmritKaur Functions in C++
7
clrscr();
cout<<"n Enter value of a:";
cin>>a;
cout<<"n Enter value of b:";
cin>>b;
cout<<"nValue of a and b IN main ()";
cout<<"na="<<a<<" t b="<<b;
//call to swap function - call by reference using pointer
swap(&a,&b);//a and b are actual parameter, their address is passed
cout<<"nValue of a and b IN main () after swap";
cout<<"na="<<a<<" t b="<<b;
}
5 10
A B
0x12 0x70
0x12 0x70
P Q
0x40
00
0x90
Afterswap() functionexecuted

More Related Content

What's hot (20)

C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
C++ functions
C++ functionsC++ functions
C++ functions
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
C function
C functionC function
C function
 
Function in c program
Function in c programFunction in c program
Function in c program
 
C++ functions
C++ functionsC++ functions
C++ functions
 
Call by value
Call by valueCall by value
Call by value
 
Function in c
Function in cFunction in c
Function in c
 
Function & Recursion in C
Function & Recursion in CFunction & Recursion in C
Function & Recursion in C
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Function in c
Function in cFunction in c
Function in c
 
Function lecture
Function lectureFunction lecture
Function lecture
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
Functions in c
Functions in cFunctions in c
Functions in c
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
 

Similar to C++ Functions Guide

Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfJAVVAJI VENKATA RAO
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4Saranya saran
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxvekariyakashyap
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptxNagasaiT
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxSangeetaBorde3
 
functionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdffunctionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdfmounikanarra3
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfTeshaleSiyum
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdfTeshaleSiyum
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfBoomBoomers
 

Similar to C++ Functions Guide (20)

Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
 
Unit 4.pdf
Unit 4.pdfUnit 4.pdf
Unit 4.pdf
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
functionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdffunctionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdf
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdf
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 
11 functions
11 functions11 functions
11 functions
 

More from Amrit Kaur

File Organization
File OrganizationFile Organization
File OrganizationAmrit Kaur
 
Introduction to transaction processing
Introduction to transaction processingIntroduction to transaction processing
Introduction to transaction processingAmrit Kaur
 
Transaction Processing
Transaction ProcessingTransaction Processing
Transaction ProcessingAmrit Kaur
 
Sample Interview Question
Sample Interview QuestionSample Interview Question
Sample Interview QuestionAmrit Kaur
 
12. oracle database architecture
12. oracle database architecture12. oracle database architecture
12. oracle database architectureAmrit Kaur
 
11. using regular expressions with oracle database
11. using regular expressions with oracle database11. using regular expressions with oracle database
11. using regular expressions with oracle databaseAmrit Kaur
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized tableAmrit Kaur
 
8. transactions
8. transactions8. transactions
8. transactionsAmrit Kaur
 
7. exceptions handling in pl
7. exceptions handling in pl7. exceptions handling in pl
7. exceptions handling in plAmrit Kaur
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functionsAmrit Kaur
 
2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATE2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATEAmrit Kaur
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive dataAmrit Kaur
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 InheritanceAmrit Kaur
 
Chapter 7 C++ As OOP
Chapter 7 C++ As OOPChapter 7 C++ As OOP
Chapter 7 C++ As OOPAmrit Kaur
 

More from Amrit Kaur (20)

File Organization
File OrganizationFile Organization
File Organization
 
Introduction to transaction processing
Introduction to transaction processingIntroduction to transaction processing
Introduction to transaction processing
 
ER diagram
ER diagramER diagram
ER diagram
 
Transaction Processing
Transaction ProcessingTransaction Processing
Transaction Processing
 
Normalization
NormalizationNormalization
Normalization
 
Sample Interview Question
Sample Interview QuestionSample Interview Question
Sample Interview Question
 
12. oracle database architecture
12. oracle database architecture12. oracle database architecture
12. oracle database architecture
 
11. using regular expressions with oracle database
11. using regular expressions with oracle database11. using regular expressions with oracle database
11. using regular expressions with oracle database
 
10. timestamp
10. timestamp10. timestamp
10. timestamp
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized table
 
8. transactions
8. transactions8. transactions
8. transactions
 
7. exceptions handling in pl
7. exceptions handling in pl7. exceptions handling in pl
7. exceptions handling in pl
 
6. triggers
6. triggers6. triggers
6. triggers
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
 
4. plsql
4. plsql4. plsql
4. plsql
 
3. ddl create
3. ddl create3. ddl create
3. ddl create
 
2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATE2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATE
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
 
Chapter 7 C++ As OOP
Chapter 7 C++ As OOPChapter 7 C++ As OOP
Chapter 7 C++ As OOP
 

C++ Functions Guide

  • 1. AmritKaur Functions in C++ 1 Chapter 5: Functions A function is a named, independent section of C++ code that performs a specific task and optionally returns a value to the calling program. A function is a part of program called by another part of a program. In a program, there are many calling function (caller) and called functions (callee). 5.1 Function Definition Function Definition is the actual function body, which contains the code that will be executed. Function definition must not end with semicolon. A function can be defined as follows Syntax: returntype functionname (parameter(s)) { //function body } Example 1: function definition to find average of 5 nos float average(int a, int b,int c, int d, int e ) { float avg; avg=(a+b+c+d+e)/5.0f; return (avg) } Here floatspecifiesreturntype; average is name of function; int a, int b, int c, int d , int e are parameters Example 2: function definition and function call #include<iostream.h> void func() { cout<<” IN FUNCTION func()”<<endl; } void main() { cout<<”IN FUNCTION main()”<<endl; func();//call to a function cout<<” BACK IN main() FUNCTION”<<endl; }
  • 2. AmritKaur Functions in C++ 2 5.2 Function Prototype A function must be defined before using it. That is, if the function definition does not precedes the function call, the function need to declare. The process of declaring function is known as function prototyping. In other words, if programmer wants to define a function after using it they have to declare the function at the top just after pre-processor directives. It includes returntype , function name and paramterlist followed by semicolon. Syntax: returntype functionname (paramtere(s)); Example 3 : float average(int a, int b,int c, int d, int e ) ; 5.3. Types of Function In C++, the function are classified into types Library Functions: Library functions are pre defined and pre compiled functions present in a library file and found in include directory with extension .h Example 4: a. sqrt(), pow() are available in header file math.h b. strlen(), strcpy() are present in string.h User defined function It is small independent program designed by user for performing the specific operations. 5.4 Elements of User defined Function Return Types Functions can return a value to the caller. When a called function sends the data back to calling program it is known as return type. If the function doesn’t return a value use void. Otherwise it can return one value by using the return keyword. The value to be returned must match with the value of return type.
  • 3. AmritKaur Functions in C++ 3 Function Name It is name of the function that is used while calling. It can be any valid identifier. Parameters or Arguments Passing a values during function call takes place through arguments. The argument(s) or parameter(s) of a function is/are the data the function must receive when called from another function. When a calling function sends the data to a called function, data is known as parameters or arguments. Types of Arguments  Actual Parameters / Arguments : Arguments listed in function calling statement. These are the values passed to function to compute.  Formal Parameters / Arguments : The arguments used in the function declaration. They receive the values supplied by calling program.  Default Parameters / Arguments : When a default value is assigned to formal arguments it is known as default arguments. Useful in case when argument is not passed in call statement Example 5: Program to find average of 5 nos #include<iostream.h> #include<conio.h> float average (int a, int b, int c, int d, int e) // formal parameters { float avg; avg=(a+b+c+d+e)/5.0; return avg; } void main() { int a,b,c,d,e; cout<<"Enter Five Numbers"; cin>>a>>b>>c>>d>>e; float result=average(a,b,c,d,e); // actual parameters cout<<"Avergare of "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" = "<<result; } 5.5 Invoking Function In C++, function can be invoked or called in one of the following ways a. Call By Value
  • 4. AmritKaur Functions in C++ 4 b. Call By Reference 5.5.1 Call By Value  In Call by Value, the value of a parameter(s) is passed.  When parameters are passed by value, the called function creates the new variables of same type and copies the argument values into it.  In call by value, the value of actual (original) parameter remain unchanged. Example: Program to swap (interchange) two numbers using call by value. #include<iostream.h> #include<conio.h> void swap(int p, int q) // p and q are formal arguments { // p is the copy of a and q is copy of b int temp; cout<<"nValue of p and q...... BEFORE swapping"; cout<<"np="<<p<<" t q="<<q; temp=p; p=q; q=temp; cout<<"nValue of p and q...... AFTER swapping"; cout<<"np="<<p<<" t q="<<q; } void main() { int a,b; clrscr(); cout<<"n Enter value of a:"; cin>>a; cout<<"n Enter value of b:"; cin>>b; cout<<"nValue of a and b IN main ()"; cout<<"na="<<a<<" t b="<<b; //call to swap function - call by value swap(a,b);//a and b are actual parameter, their value is passed cout<<"nValue of a and b IN main () after swap"; cout<<"na="<<a<<" t b="<<b; } 5 10 A B 0x12 0x70 5 10 A B 0x12 0x70
  • 5. AmritKaur Functions in C++ 5 5.5.2 Call By Reference using an Alias  A reference provides an alias (alternate names) for the variable.  In call be reference using alias, a reference of the parameter in the calling program is passed.  While passing, call by reference, the value of actual (original) variable changes because there is only one copy of data is maintained with two different names. Example: Program to swap (interchange) two numbers using call by reference using alias. #include<iostream.h> #include<conio.h> void swap(int &p, int &q)// p and q are formal arguments { // ampersand indicates p is alias of a // and q is alias of b int temp; cout<<"nValue of p and q...... BEFORE swapping"; cout<<"np="<<p<<" t q="<<q; temp=p; p=q; q=temp; cout<<"nValue of p and q...... AFTER swapping"; cout<<"np="<<p<<" t q="<<q; } void main() { int a,b; clrscr(); cout<<"n Enter value of a:"; cin>>a;
  • 6. AmritKaur Functions in C++ 6 cout<<"n Enter value of b:"; cin>>b; cout<<"nValue of a and b IN main ()"; cout<<"na="<<a<<" t b="<<b; //call to swap function - call by reference using alias swap(a,b);//a and b are actual parameter, their value is passed cout<<"nValue of a and b IN main () after swap"; cout<<"na="<<a<<" t b="<<b; } 5.5.3 Call By Reference using an Pointers  In call be reference using pointers, an address of actual (original) parameter is passed to the calling program.  While passing, call by reference, the value of actual (original) variable changes because there is only one copy of data is maintained. Example: Program to swap (interchange) two numbers using call by reference using pointers. #include<iostream.h> #include<conio.h> void swap(int *p, int *q)// p and q are formal arguments { // p contain address of a // q contain address of b int temp; cout<<"nValue of p and q...... BEFORE swapping"; cout<<"np="<<*p<<" t q="<<*q; temp=*p; *p=*q; *q=temp; cout<<"nValue of p and q...... AFTER swapping"; cout<<"np="<<*p<<" t q="<<*q; } void main() { int a,b; Afterswap() functionexecuted 10 5 P Q A B
  • 7. AmritKaur Functions in C++ 7 clrscr(); cout<<"n Enter value of a:"; cin>>a; cout<<"n Enter value of b:"; cin>>b; cout<<"nValue of a and b IN main ()"; cout<<"na="<<a<<" t b="<<b; //call to swap function - call by reference using pointer swap(&a,&b);//a and b are actual parameter, their address is passed cout<<"nValue of a and b IN main () after swap"; cout<<"na="<<a<<" t b="<<b; } 5 10 A B 0x12 0x70 0x12 0x70 P Q 0x40 00 0x90 Afterswap() functionexecuted