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-
Your answer
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
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...... :)
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
–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.
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...