+ 2

While performing a swap function ( passing by reference) do we swap the pointer or their values?

It's quite confusing as the same symbol is used for calling the value and defining a pointer i.e. *

6th Feb 2018, 6:04 PM
Jupjyot Khosla
Jupjyot Khosla - avatar
4 Antworten
+ 7
Normally, you swap values. It is much easier to do. To swap pointers, you would need a linked list, array of pointers, or similar data structure to process, where the pointers are maintained by you. You can't swap pointers the compiler assigns.
6th Feb 2018, 7:10 PM
John Wells
John Wells - avatar
6th Feb 2018, 10:29 PM
John Wells
John Wells - avatar
+ 2
Can you explain a bit about swap by pointer method too. It would be helpful.
6th Feb 2018, 10:02 PM
Jupjyot Khosla
Jupjyot Khosla - avatar
+ 2
Thank you! I appreciate your work.
7th Feb 2018, 2:48 PM
Jupjyot Khosla
Jupjyot Khosla - avatar