Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
how do i swap using reference variable in c++ ?
–1
vote
asked
Jun 5, 2018
by
komol
-help-plz-
Please
log in
or register to answer this question.
2 Answers
0
votes
answered
Jun 5, 2018
by
Saurabh
(
600
points)
Best answer
#include<iostream>
using namespace std;
void swap(int &a,int &b)
{
int t;
t=a;
a=b;
b=t;
}
int main(void)
{
int x=10;
int y=23;
cout<<"Before swap";
cout<<x<<y;
swap(x,y);
cout<<"After swap";
cout<<x<<y;
return 0;
}
commented
Jun 5, 2018
by
komol
thank you...... :)
Please
log in
or register to add a comment.
–1
vote
answered
Jun 5, 2018
by
Nikhil Kakkireni
(
320
points)
#include<stdio.h>
void main()
{
int i,j,k;
printf("enter first value\n");
scanf("%d",&i);
printf("enter second value\n");
scanf("%d",&j);
k = i;
i = j;
j = k;
printf("First number is : %d\n",i);
printf("Second number is : %d\n",j);
}
commented
Jun 5, 2018
by
Saurabh
(
600
points)
Here is no use of reference variable.
Please
log in
or register to add a comment.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...