GTU Data Structure Practical - 1
Introduction to pointers. Call by Value and Call by reference.
Call by Value
#include
void swap(int,int);
int main()
{
int a,b;
printf("\nEnter a Value of A=");
scanf("%d",&a);
printf("\nEnter a Value of B=");
scanf("%d",&b);
swap(a,b);
printf("\nOld Values:");
printf("A=%d B=%d \n",a,b);
}
void swap(int p,int q)
{
int tmp;
tmp=p;
p=q;
q=tmp;
printf("New Values After Swap:");
printf("A=%d B=%d",p,q);
}
Output
![Call by Value and Call by reference Program Call by Value and Call by reference Program](https://gtupractical.com/wp-content/uploads/2022/10/DS-1.png)
Call by Reference
#include
void swap(int*,int*);
int main()
{
int a,b;
printf("\nEnter a Value of A=");
scanf("%d",&a);
printf("\nEnter a Value of B=");
scanf("%d",&b);
swap(&a,&b);
printf("\nOld Values:");
printf("A=%d B=%d \n",a,b);
}
void swap(int *p , int *q)
{
int tmp;
tmp=*p;
*p=*q;
*q=tmp;
printf("New Values After Swap:");
printf("A=%d B=%d",*p,*q);
}
Output
![Call by Value and Call by reference Program Call by Value and Call by reference Program](https://gtupractical.com/wp-content/uploads/2022/10/DS-1-O1.png)