Q. By how many ways we can call functionin c or c++?
Ans- There are three ways to call a function in C or C ++
Call By Value
* In this if formal arguements are changed then
actual arguements are not changed.
Ex.
#include<iostream.h>
void main()
{
void test (int , int)
int a=5,b=6;
test(a,b);
cout<<a<<b;
}
void test (int x,int y)
{
x=x+10;
y=y+10;
}
Output : 5 , 6 .
Call By Refrence
* In C or C ++ we can also call a function by
passing refrencevariable so that if formal
arguements are cahanged then actual
arguements are changed.
Refrence Variable -- It is an alias of another
variable , both represent
same location of value.
syntax
datatype &variable1=variable2
Ex.
#include<iostream.h>
void main()
{
void test (int&,int&)
int a=5 , b=6;
test(a,5);
cout<<a<<b;
}
void test (int &x,int &y)
{
x=10+x;
y=y+10;
}
Output : 15 , 16 .
Call By Address
Ex.
#include<iostream.h>
void main()
{
void test (int*,int*)
int a=5 , b=6;
test(&a , &b);
cout<<a<<b;
}
void test (int &x,int &y)
{
*x=10+ *x;
*y= *y + 10;
}
Output : 15 , 16 .
⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕
Thank You
Patna University 1917
⇒⇒ If any question just ask me in comment box ⇐⇐
Jai Hind Jai Bharat.
Ans- There are three ways to call a function in C or C ++
Call By Value
* In this if formal arguements are changed then
actual arguements are not changed.
Ex.
#include<iostream.h>
void main()
{
void test (int , int)
int a=5,b=6;
test(a,b);
cout<<a<<b;
}
void test (int x,int y)
{
x=x+10;
y=y+10;
}
Output : 5 , 6 .
Call By Refrence
* In C or C ++ we can also call a function by
passing refrencevariable so that if formal
arguements are cahanged then actual
arguements are changed.
Refrence Variable -- It is an alias of another
variable , both represent
same location of value.
syntax
datatype &variable1=variable2
Ex.
#include<iostream.h>
void main()
{
void test (int&,int&)
int a=5 , b=6;
test(a,5);
cout<<a<<b;
}
void test (int &x,int &y)
{
x=10+x;
y=y+10;
}
Output : 15 , 16 .
Call By Address
Ex.
#include<iostream.h>
void main()
{
void test (int*,int*)
int a=5 , b=6;
test(&a , &b);
cout<<a<<b;
}
void test (int &x,int &y)
{
*x=10+ *x;
*y= *y + 10;
}
Output : 15 , 16 .
⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕⇕
Thank You
Patna University 1917
⇒⇒ If any question just ask me in comment box ⇐⇐
Jai Hind Jai Bharat.
3
ReplyDeleteThis comment has been removed by the author.
DeleteAnswer please
ReplyDelete