C++ Program to Exchange Values of Two variables using Pointer

C++ program to exchange values of two variables (Swapping) using pointer. This program uses a function called exchange(int*,int*) that takes two argument as integer pointers. The variables are passed by reference method and hence, the swapping done at the exchange function will reflect in the main method also.

#include<iostream>
#include<conio.h>
using namespace std;
void exchange(int*, int*);
void main()
{   
        int x,y;
        cout<<“Enter x :”;
        cin>>x;
        cout<<“nEnter y:”;
        cin>>y;
        cout<<“Before Exchange : x = “<<x<<” y = “<<y<<“nn”;
        exchange(&x,&y);  //Calling Exhcange function to swap
        cout<<“After Exchange : x = “<<x<<” y = “<<y<<“nn”;
        getch();
}
//No need to return any values since the variables are already affected.
void exchange(int *a, int *b)
{
        int t;
        t = *a;   //Saving data in first variable to an intermediate one
        *a = *b;  //Saving second variable to first
        *b = t;   //Saving intermediate variable to second
}

[Compiled using Visual Studio]

Comments

53 responses to “C++ Program to Exchange Values of Two variables using Pointer”

  1. … [Trackback]

    […] Find More Info here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  2. … [Trackback]

    […] Read More on on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  3. … [Trackback]

    […] Read More on on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  4. … [Trackback]

    […] Read More to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  5. … [Trackback]

    […] Find More on on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  6. … [Trackback]

    […] Read More to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  7. … [Trackback]

    […] Information on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  8. … [Trackback]

    […] Find More Information here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  9. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  10. … [Trackback]

    […] Read More Information here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  11. … [Trackback]

    […] Read More Info here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  12. … [Trackback]

    […] Info on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  13. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  14. … [Trackback]

    […] Find More on on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  15. … [Trackback]

    […] Info to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  16. … [Trackback]

    […] Read More here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  17. … [Trackback]

    […] Read More here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  18. … [Trackback]

    […] Information on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  19. … [Trackback]

    […] Find More here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  20. … [Trackback]

    […] Here you will find 74538 more Info to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  21. … [Trackback]

    […] Read More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  22. … [Trackback]

    […] Read More here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  23. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  24. … [Trackback]

    […] Read More on to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  25. … [Trackback]

    […] Find More Information here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  26. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  27. … [Trackback]

    […] Read More on on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  28. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  29. … [Trackback]

    […] Read More Information here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  30. … [Trackback]

    […] Read More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  31. … [Trackback]

    […] Read More here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  32. … [Trackback]

    […] Info on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  33. … [Trackback]

    […] There you can find 55769 more Info on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  34. … [Trackback]

    […] Read More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  35. … [Trackback]

    […] Find More to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  36. … [Trackback]

    […] Read More to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  37. … [Trackback]

    […] Read More here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  38. … [Trackback]

    […] Info to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  39. … [Trackback]

    […] Read More Information here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  40. … [Trackback]

    […] Here you can find 2514 additional Info on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]

  41. can you get enclomiphene over the counter

    cheapest buy enclomiphene generic enclomiphene

  42. discount androxal generic extended release

    ordering androxal price canada

  43. buy generic dutasteride online canada

    how to order dutasteride cheap trusted

  44. order flexeril cyclobenzaprine cost at costco

    discount flexeril cyclobenzaprine purchase usa

  45. order gabapentin price usa

    discount gabapentin generic is good

  46. ordering fildena buy japan

    online order fildena cheap from canada

  47. buy cheap staxyn generic discount

    order staxyn generic online canada

  48. buy itraconazole usa mastercard

    purchase itraconazole purchase to canada

  49. buy avodart price new zealand

    buy cheap avodart low cost

  50. how to buy rifaximin american pharmacy

    buying rifaximin cheap drugs

  51. cheapest buy xifaxan purchase from uk

    how to buy xifaxan canadian sales

  52. jsem ナセena, kterテ。 mテ。 emfyzテゥm s nテュzkテスm hemo atd. dr chce pナ册depsat kamagra

    objednejte kamagra bez lテゥkaナ冱kテゥho pナ册dpisu od naナ。テュ lテゥkテ。rny

Leave a Reply