by Dinesh Thakur Category: C Programming (Pratical)

This is C program where user asks to interchange the two values with each other using Call by reference method. Declaring the required variable for functionality. Then after user declare void swap() function that which will give the reference to other class for interchange. After that user call the function that declare void swap() then using method to interchange the value of variables with the help of pointer concept to declare pointer type variables that are useful while using the call by reference method. In the end the result has to be display on the screen.

Problem statement:

This is C program that asks the user to interchange the value of two variables with use of call by reference Method.

  1. Declaring variables.
  2. Make function.
  3. Calls the function.
  4. Using Interchange method for value swapping.
  5. Display result on the screen.

Here is C source code for interchange value of two variables using Call by reference Method. The output of this program shown below. 

#include<stdio.h>

void main()
{
     int a=40;
     int b=70;
     void swap(int *x,int *y);
     clrscr();
     printf("a=%d,b=%d",a,b);
     swap(&a,&b);
     printf("\nAfter Swaping Result is :\na=%d  b=%d ",a,b);
     getch();
}
     void swap(int *x,int *y)
       {
              int t;
              t=*x;
              *x=*y;
              *y=t;
       } 

Interchange Values of 2 no: using Call By Reference

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content