C Programs: (no
Pass-By-Reference)
Pass-By-Value:
#include <stdio.h>The output will bevoid swap1(int a, int b)
{
int temp = a;printf(" Beginning of subprogram\n");a = b;
printf("a= %d \n", a);
printf("b= %d \n", b);
b = temp;printf(" Ending of subprogram\n");}
printf("a= %d \n", a);
printf("b= %d \n", b);main()
{
int c=1;
int d=0;printf("Before call \n");swap1(c, d);
printf("c= %d \n", c );
printf("d= %d \n", d);printf("After call \n");}
printf("c= %d \n", c );
printf("d= %d \n", d);
Before callPass-By-Pointers:
c= 1
d= 0
Beginning of subprogram
a= 1
b= 0
Ending of subprogram
a= 0
b= 1
After call
c= 1
d= 0
#include <stdio.h>The output will bevoid swap2(int *a, int *b)
{
int temp = *a;printf(" Beginning of subprogram\n");*a = *b;
printf("a= %d \n", *a);
printf("b= %d \n", *b);
*b = temp;printf(" Ending of subprogram\n");}
printf("a= %d \n", *a);
printf("b= %d \n", *b);main()
{
int c=1;
int d=0;printf("Before call \n");swap2(&c, &d);
printf("c= %d \n", c );
printf("d= %d \n", d);printf("After call \n");}
printf("c= %d \n", c );
printf("d= %d \n", d);
Before call
c= 1
d= 0
Beginning of subprogram
a= 1
b= 0
Ending of subprogram
a= 0
b= 1
After call
c= 0
d= 1