Aliasing Arrays

If ‘a’ is an array, we can assign it to ‘b’, as:

b = a

This is a simple assignment that does not make any new copy of the array ‘a’. It means, ‘b’ is not a new array and memory is not allocated to ‘b’. Also, elements from ‘a’ are not copied into ‘b’ since there is no memory for ‘b’. Then how to understand this assignment statement? We should understand that we are giving a new name ‘b’ to the same array referred by ‘a’. It means the names ‘a’ and ‘b’ are referencing same array. This is called ‘aliasing’.

example image for aliasing

‘Aliasing’ is not ‘copying’. Aliasing means giving another name to the existing object. Hence, any modifications to the alias object will reflect in the existing object and vice versa.