✅ [] brackets explanation
Hey can somone explain to me why this dummy1 is an last letter of the string that we read ? I might be dump but for me imie.lenght is and number of letters in string like 4 and when i substract 1 it should print 3 but it gives me letter. It is always when i use this [] brackets.
15 Replies
first things first, the code you just posted isn't valid, as you can see from the red squiggly line
second - arrays are what we call "zero-indexed"
an array with a single item in it will have
length
1, but we access that item with array[0]
thus, array.length - 1
Oh so by using [] we create an array yes ?
no
we access an array
remember, strings are actually
char[]
meaning all strings are arrays of charactersAh yea u are right it is an array of chars
Well, it isn't actually an array of chars, but it supports using the array syntax to access individual chars
Wired question can i access this way a bit of an int number ?
No. Ints don't support doing that
You can create a BitArray though
Ok thanks then i will read a bit about arrays and accesing stuff with [] brackets ^^
wat?
wat
yeah I'm gonna look at whatever that link is
you should, it's a classic
tv
no thanks
anyway
back to the topic?
What topic? You just said "wat"