From bbd4b903dc1e1909ce6748975ea15feae7546cc5 Mon Sep 17 00:00:00 2001 From: yashasvi25 <37210366+yashasvi25@users.noreply.github.com> Date: Tue, 15 Oct 2019 22:54:02 +0530 Subject: [PATCH] Add files via upload Swapping two numbers using pointers --- .../swap_2_numbers_using_pointers.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Swap-without-third-variable/swap_2_numbers_using_pointers.cpp diff --git a/Swap-without-third-variable/swap_2_numbers_using_pointers.cpp b/Swap-without-third-variable/swap_2_numbers_using_pointers.cpp new file mode 100644 index 0000000..6882bba --- /dev/null +++ b/Swap-without-third-variable/swap_2_numbers_using_pointers.cpp @@ -0,0 +1,18 @@ +#include +using namespace std ; + +void swap_numbers(int* a,int* b) +{ + *a = *a + *b ; + *b = *a - *b ; + *a = *a - *b ; + +} + +int main() +{ + int *x = 10, *y = 20 ; + swap_numbers(x , y ) ; + cout<<*x<