There are basically three ways of passing the values -----
1)Pass by value
2)Pass by reference
3)Pass by pointer
1)Pass by value----actual parameters r passed to formal parameters to another address defined in called function...address is not actually passed.....
for e.g.
#include<stdio.h>
int func(int);
int main()
{
int a=5,sum;
sum=func(a);
printf("sum=%d\n",sum);//returned value is catched by sum variable which is 60...
printf("\nafunc=%d",a);//but at main address actual parameter remains same i.e.a=5 prints in output...
return 0;
}
int func(int b)//variable is passed but address is diffrent its like miscarage of heart occurs at one address(place)& its cure i.e. hospital at another address
{
b=60;//although value of variable is changed
printf("\nbfun=%d",b);//b=60 will be printed at this address
return b;
}
Pass by address-:::-----As name implements that because address is passed of variable in function will be catched by a pointer bcz only pointer may hold that address ....
for e.g.
#include<stdio.h>
#include<string.h>
void display(char*);
int main()
{
char arr[7]={"ANUBALA"};
int i;
for(i=0;i<=7;i++)
{
display(&arr[i]);//address of string is passed in fun display
printf("_________________%c\n",arr[i]);//we will see we have no need to return the value ...value at address of actual parameters is changed ...so arr[i] will also print changed value i.e.a....
}
return 0;
}
void display(char *x)//address is holded by a pointer where *x represents value at address
{
*x='a';//value of characters of string is changed ....
printf("%c\n",*x);//changed value is printed
}
Pass by pointer:::-------In function ...we actually pass a pointer which is pointing to some address...