Forums Register Login

array declaration and creation

+Pie Number of slices to send: Send
Hi,

I have a doubt in the following code. Please clear my doubt



Upto line 3 I have no problem. I well understood the concept behind them. The compiler generated error messages at line 4 and line 5 saying illegal start of expression.
+Pie Number of slices to send: Send
 


array2[0] = {1,2,3,4,5}; // line 4
array2[1] = {6,7,8,9,10}; // line 5




array2 is a Two dimensional array
array2[0] - holds only address of a one dimensional array or null
array2[0][0] - holds only values

but in the above case you are assigning values where it is expecting address
changte it to

array2[0][0] = {1,2,3,4,5}; // line 4
array2[0][1] = {6,7,8,9,10}; // line 5
+Pie Number of slices to send: Send
Hi Vidya,


array2[0][0] = {1,2,3,4,5}; // line 4
array2[0][1] = {6,7,8,9,10}; // line 5
--------------------



The above code change you have suggested did not work.
Below is the code that works. But I donot know the reason behind it.


When we are creating anynomous array and assign that reference to
array2[0] its working.

Can anyone please tell what differnce between line1 and line2, and when to use which one.
int[] a1 = {1,1,1,1}; //line1
int[] a1 = new int[] {1,1,1,1}; // line2

Thanks
Shyam Ramineni
+Pie Number of slices to send: Send
Hi



You can read this
or this for more information.
[ August 05, 2005: Message edited by: George Bolyuba ]
This tiny ad is wafer thin:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 718 times.
Similar Threads
Doubt in this()
doubt in pass by refrence
Doubt........
doubt in for loop
Arrays doubt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:05:08.