problem with swaping the numbers in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

problem with swaping the numbers in c++

int A{10}; int B{20}; int *num1{&A}; int *num2{&B}; int *temp{num1}; num1 = num2 ; num2 = temp; Here I have observed that *num1 and *num2 swapped but not A & B........ why??????

28th May 2021, 5:01 PM
saurabh
saurabh - avatar
1 Answer
+ 1
//Instead Int *temp{num1}; //Use Int *temp = num1; Got idea from this link. Plz check it out https://stackoverflow.com/questions/15672805/c-swapping-pointers Hope it helps you
28th May 2021, 6:25 PM
Aysha
Aysha - avatar