Q) - Passing Parameters:: 1. Call by Value or Pass by Value
Q) - Passing Parameters:: 1. Call by Value or Pass by Value
Q) - Passing Parameters:: 1. Call by Value or Pass by Value
2. Call by Reference:
In the call by value any changes made to formal arguments will not effected to the actual
arguments. This is the one of the disadvantage of call by value. This disadvantage is overcome with call
by reference.
In call by reference the value send to the called function, reference is send to the called function.
So the changes made to the formal arguments will also effect to the actual arguments. This is because
the manipulation has been done through the address (or) via address. In this way we can avoid the
disadvantage of call by value.
#include<stdio.h>
#include<conio.h>
Page- 2
Some times we need to send more values at a time to the called function, in such type of cases
the arrays are suitable to send as an argument to the called function.
To use the arrays as an argument to the functions we need to send the name of the arrays as an
argument.
The following program illustrates the above concept.
#include<stdio.h>
#include<conio.h>
void ABC(int[],int);
void main()
{
int a[5]={10,20,30,40,50}
int n=5, i;
ABC(a,n);
getch();
}
void ABC(int b[], int x)
{
int i;
printf("\nThe array elements are....\n");
for(i=0;i<=x-1;i++)
{
printf("%d\t",b[i]);
}
}
Output
Recursive function:
Recursive function is the process of defining something in terms of itself. a function is called by
itself is known as a recursive function and this process is known as recursion.
The recursive functions are very useful for solving mathematical problems.
They are used for calculating factorial of a number, Fibonacci series etc .
Example:
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n=5; int f;
f=fact(n);
printf("\nFactorial %d", f);
getch();
}
int fact(int n)
{
if(n==0)
return 1;
else
return n*fact(n-1);
}
Output:
int func1(int n)
Page- 4
{
if(n==0)
return n;
else
return fun2(n);
}
int func2(int x)
{
return func1(x-1);
}
Output
3. Recursion will terminated when the 3. It is terminated when the loop is fail
case is recognized.
6. Infinity recursion can crash the system 6. Infinity loops uses cpu cycles repeatedly.
A block scope is also known as local variable. A variable that can be declared inside the block(({})
(or) inside the main() function is also called Block scope.
Ex:
void main()
{
int a=10; //Local(block) variable
printf(%d, a);
getch();
Page- 5
}
2. Program Scope(Global)
A Program scope is also known as global variable. A variable that are declared outside of the
block (or) main() function is also called as program scope.
Ex:
int c; //Global variable
void main()
{
int =10, b=20;
c=a+b;
printf(%d, c);
getch();
}
3. Function Scope
It is indicate that a variable is active and visible from the beginning to the end of a
function. In C only GOTO labes have uses the labels.
EX:
void main
{
-------
Loop: //function scope
-------
goto loop;
getch();
}
4. File Scope
When a global variable is accessible until the end of the file, the variable is said to have file
scope. The file scope variable can cave declared with the static keyword.
EX:
static int x=20;