Documente Academic
Documente Profesional
Documente Cultură
int main()
{ int num1=11,num2=22;
int result;
result = sum(num1,num2);
printf("\nResult : %d",result);
return(0);
}
Explanation
Function Nane sum
Formal Parameter 1 n1
Formal Parameter 2 n2
// main function that doesn't receive any parameter and returns integer.
int main(void)
{
int a = 10, b = 20;
int main(void)
{
int x = 20;
fun(x);
printf("x = %d", x);
return 0;
}
Call by Reference
# include <stdio.h>
void fun(int *ptr)
{ Output:
*ptr = 30; x = 30
}
int main()
{
int x = 20;
fun(&x);
printf("x = %d", x);
return 0;
}
Swaping by Call by Value
void main()
{ int a=10,b=20;
printf("value of a and b before swaping is%d %d",a,b);
swap(a,b);
printf("\n value of a and b after swaping function is%d %d",a,b);
}
swap(int x,int y)
{ int t;
printf("\n value of x and y before swaping is%d %d",x,y);
t=x;
x=y;
y=t;
printf("\n value of x and y after swaping is%d %d",x,y); }
Swaping by Call by Reference
void main()
{ int a=10,b=20;
printf("value of a and b before swaping is%d %d",a,b);
swap(&a,&b);
printf("\n value of a and b after swaping function is%d %d",a,b);
getch();
}
swap(int *x,int *y)
{ int t;
t=*x;
*x=*y;
*y=t;
}