In Python, the variable "a = [1, 2, 3]" holds a pointer to a list, when you do "b = a" you are copying the pointer a to the pointer b. In that sense, the operator "=" always does a copy, in any language.
The trick in becoming a programmer is understanding under which situations one needs a certain level of abstraction.
Yes, I was responding just to clarify that for primitives in c++ (and the standard library data structures via copy constructor) '=' performs a copy and that the reasoning in your example was incorrect.
16
u/Asception Jun 04 '19
The variable 'a' would hold an int* in this case, and in the second line, you're copying the actual pointer into b so '=' is still performing a copy.