✅ [] 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
Pobiega
Pobiega14mo ago
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
zielona_pomarańcza
Oh so by using [] we create an array yes ?
Pobiega
Pobiega14mo ago
no we access an array remember, strings are actually char[] meaning all strings are arrays of characters
zielona_pomarańcza
Ah yea u are right it is an array of chars
canton7
canton714mo ago
Well, it isn't actually an array of chars, but it supports using the array syntax to access individual chars
zielona_pomarańcza
Wired question can i access this way a bit of an int number ?
canton7
canton714mo ago
No. Ints don't support doing that You can create a BitArray though
zielona_pomarańcza
Ok thanks then i will read a bit about arrays and accesing stuff with [] brackets ^^
d1ag0n
d1ag0n14mo ago
wat? wat
d1ag0n
d1ag0n14mo ago
d1ag0n
d1ag0n14mo ago
yeah I'm gonna look at whatever that link is
blinkbat
blinkbat14mo ago
you should, it's a classic
d1ag0n
d1ag0n14mo ago
tv no thanks anyway back to the topic?
canton7
canton714mo ago
What topic? You just said "wat"