✅ [] 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
Pobiega2y 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
Pobiega2y 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
canton72y 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
canton72y 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
d1ag0n2y ago
wat? wat
d1ag0n
d1ag0n2y ago
d1ag0n
d1ag0n2y ago
yeah I'm gonna look at whatever that link is
blinkbat
blinkbat2y ago
you should, it's a classic
d1ag0n
d1ag0n2y ago
tv no thanks anyway back to the topic?
canton7
canton72y ago
What topic? You just said "wat"
Want results from more Discord servers?
Add your server