Swap Two Variable using Call by Reference

-- Leave a Comment
Hello Here is a C program to Swap Two integer variable using call by reference.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
void swap (int *o, int *p)
{
    int tmp;
    tmp = *o;
    *o = *p;
    *p = tmp;
}
main ()
{
    int a,b;
    printf("Enter the value of A:- ");
    scanf("%d",&a);
    printf("Enter the value of B:- ");
    scanf("%d",&b);
    printf("\nBefore Swap:-\nA = %d\nB = %d",a,b);
    printf("\nAfter Swap:-");
    swap(&a, &b);
    printf("\nA = %d\nB = %d",a,b);
}


Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University, NCIT. Open Source Enthusiastic.

0 comments:

Post a Comment