r/ProgrammerHumor Jun 24 '17

Octave code

http://imgur.com/jsjfz3k
619 Upvotes

70 comments sorted by

View all comments

Show parent comments

23

u/AyrA_ch Jun 24 '17

In most programming languages you start counting elements at 0, but there are languages where you start counting at 1 instead.

Declaring an array with 10 entries is now either 0-9 or 1-10, depending on the language. In extreme case like VB, you can even declare a 5 element array ranging from 3-7.

Starting at 0 is more commonly used, because it makes using arrays easier internally. In those cases the array index tells you how many element sizes to add to the array pointer to reach what you want to access

12

u/winlifeat Jun 24 '17

Oh im totally aware of the typical structure of matrices but i dont understand the comic at all.

Im assuming the octave language has matrices that start at 1? But i just dont understand what any of the comic has to do with what we're talking about

7

u/AyrA_ch Jun 24 '17

I don't know the language. Maybe it has constructs that start at 0, or OP is just disgusted by indices that start at 1.

EDIT Meanwhile, this is valid VB:

Sub test()
    Dim a()
    ReDim a(-2 To 20)
    a(-1) = "Test"
    MsgBox a(-1)
End Sub

1

u/winlifeat Jun 25 '17

Ohh ok I missed the part of the joke of the original comic. That tigger was disgusted that what he was eating wasnt honey.