public class Program { public static void main(String[] args) { int x[]={110,20,30,40,50,70}; int y[]; y=x; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

public class Program { public static void main(String[] args) { int x[]={110,20,30,40,50,70}; int y[]; y=x;

Why this output come

27th Sep 2019, 3:24 PM
Anuj Patel
Anuj Patel - avatar
1 Answer
+ 5
Hy Anuj Patel You didn't specified the output, if you will make some change in value of elements of array y then same change will come in elements of array x as you are assigning reference of array x in y(they are pointing to same memory location). To avoid this problem, you can declare variable y of same length l as of x and then run a loop from 0 to l-1 & assign value for each index in y.
27th Sep 2019, 6:37 PM
Gaurav Agrawal
Gaurav Agrawal - avatar