google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a c program to demonstrate the pass by reference mechanism - 2nd puc computer science

Write a c program to demonstrate the pass by reference mechanism

pass by reference in c,call by reference in c program,pass by reference in c example

Write a c program to demonstrate the pass by reference mechanism

#include<stdio.h>

#include<conio.h>

void main()

{

void swap(int *,int *);

int a,b;

clrscr();

printf("Enter two numbers:\n");

scanf("%d%d",&a,&b);

printf("Before calling the function a=%d and b=%d\n",a,b);

swap(&a,&b);

printf("After calling the function a=%d and b=%d",a,b);

getch();

}

void swap(int *x, int *y)

{

int temp;

temp=*x;

*x=*y;

*y=temp;

}

Output:

Enter two numbers:

2                                                                              

4                                                                              

Before calling the function a=2 and b=4                                        

After calling the function a=4 and b=2
Write a c program to demonstrate the pass by reference mechanism Write a c program to demonstrate the pass by reference mechanism Reviewed by Vision Academy on December 14, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.