Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array element

 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static char ch;//implicitly \u0000 default value is assigned for ch
int[] ia = new int[1];
ia[ch]=5;//line 3
SOP(ia[ch]);

at line 3,i am thinking like ia[\u0000] is executed.\u0000 is emptyspace.
then how come ia[0] is printed.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's your mistake: "\u0000 is emptyspace"

ch is 16 zero bits, and that is 0. The 16 bits are widened to 32 bits but that still results in the array index being 0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic