• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Arrays

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In the above line of code, is it true tht a5 represents a single dimension array and a6 represents two dimensional array?
pls correct me if iam wrong.
Regards
Vineela
 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vineela,

is it true tht a5 represents a single dimension array and a6 represents two dimensional array?


it's true, try the following to verify:

Greetings
Gian Franco
[ April 02, 2004: Message edited by: Gian Franco Casula ]
 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gian,
Thanks. I got it.
Regards
Vineela
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
that's right, but be careful .....
int [] a , b [] ; // a 1dimension, b 2 dimensions
int [] a , [] b ; // Compiler error!
pay close attention!
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This confuses me... Grr..!
Is it because after the "comma" && the brackets are "after" variable b?
what about three? Such as: int []a,b[],c[] ??
Thanks in advance. For some reason this syntax has got me confused.
 
fethi makhlouf
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
don't be confused! it needs just a close attention
Look to that :
int a , b , c ; // a b c are int!
int [] a , b ,c ; // a b c are int []
now if you want to tell the compiler you are defining int [] a b and int [] [] c in the same line :

int [] a , b, [] c ; // is false
int [] a , b, c [] ; // is true!
why ? 'cause just after comma, the compiler waits for an identifier, when it finds [] he stops to tell you there is an error!
is it clear?
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scot,
Remember the rules.
1. The brackes for an array declaration can be placed after the type or after the identifier.
2. If the bracket is placed after the type, that dimenstion applies to all identifier's in that statement.
Cheers
-Suresh
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic