Please any one can explain me in the following code, why the line 2 give compliler error..... ---------------------------------- int a1,a2; // 1 int a3,a4; // 2 int a5,a6; // 3 int a7,a8; // 4 ----------------------------------- The line2 similar to
int a3; int a4;
Then why it leads to compiler error.
" Don't be afraid of pressure. Remember that pressure is what turns a lump of coal into a diamond... " <br /> <br />Thanks & Regards...<br />Sakthi<br />SCJP1.4, OCA
Joined: Mar 18, 2005
Hi, In line 2 any valid identifier is expected here. So compiler throws an error message.
int a3, a4; // 2 change this line to int [a3],a4; // It compile without any error message
Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>
Joined: Jun 25, 2004
The declaration of the array
int a3,a4; // 2
shows compile time error as the array brace has to be put after the variable. the array a3 declaration is correct since it immedietly follows the datatype, whereas a4 comes after coma. the correct declaration would be
int a3,a4; // 2
Hope this solves ur doubt.
have will, have everything...
Joined: Mar 29, 2005
I am still not clear..
Both a1 and a2 are type int.
Then why not in arrays as,
int a1,a2; plz help me...
Joined: Apr 04, 2005
int  a1; the above statement means that a1 is of type int.
int a1 , a2; The above statement means that a1 and a2 both are of type int.
so int becomes the type and a1 and a2 becomes variables.
if we write int a1; this means a1 is an array of type int(which itself is an array) therefore a1 is of type int i.e. a 2-d array.
but if we write int a1 , a2; here a1 is the name of the variable but a2 cannot be resolved as the compiler expects a variable name and  are not allowed in the name of the variable.
Manish Nijhawan<br />B-Tech
Joined: Mar 01, 2005
hi is a2 is two dimensional while a1 is single dimnesional one.
Joined: Aug 25, 2004
int a3,a4; // is wrong, need a primitive/object type on left of a4.