If I place the [] after the datatype then does it mean that all the variables declared thereafter will be arrays? I mean in the above code 'arr ' is an array but what about 'num'? 'num' is also an declared array?
I am geting compiler error 'incompatible type' at line marked 1.
But If I do:
then 'num' is just a variable of type int, not an array. No compiler error is there.
If I place the [] after the datatype then does it mean that all the variables declared thereafter will be arrays? I mean in the above code 'arr ' is an array but what about 'num'? 'num' is also an declared array?
I am geting compiler error 'incompatible type' at line marked 1.
But If I do:
then 'num' is just a variable of type int, not an array. No compiler error is there.
I'm not confortable with your programming style. even if it gives the desired results, it seems like bad practice to have int arr[], num; in one line, mixing data types like that. if you want arr to be an array and num to be an integer, I'd put them on separate lines. To me that makes it clearer what you want to do. But that is more about style than correctness I guess.
also in the first example I would have coded int[] arr, num; to make them both arrays, for clarity, but It sounds like that does the same thing, makes them both arrays.
W Pearce
Ranch Hand
Joined: Jan 06, 2009
Posts: 32
posted
0
Akanksha Joy wrote:You mean to say that it matters where we place the square brackets?
Yes, for example in your first code snippet, putting [] before variable names makes them all arrays. But if you had something like thisonly j and l are made into arrays, while k is a normal int type. I would highly recommend following Fred's suggestion and putting these on separate lines.for readability's sake and to cause less confusion.