+ 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. *
4 Respostas
+ 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.
+ 4
Here is an example
https://code.sololearn.com/c0MUdT79DOuf
+ 2
Can you explain a bit about swap by pointer method too. It would be helpful.
+ 2
Thank you! I appreciate your work.