Google interview phone question:>Why does the array index start with 0?99% of /g/ will fail this.
>>108520312I look like that
>>108520322 (checked)You will never be a Korean woman.
>>108520335Mean
>>108520312
I'm at a loss for words and I'm too embarrassed to google it
>>108520312I got one>mechanic interview question:>what are the chemical components of gasolinemost mechanics will fail this
>>108520312Because address space was once tiny? It's legacy. Like most things in software are.
Because C decided it starts at 0 and C got popular. Many contemporary languages like fortran start at 1 and in basic you can start from anywhere with option base.
>>108520312Because Dijkstra said so.https://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831.html
>>108520470Carbon and hydrogen.If you don't know this you cannot be any kind of mechanical anything . Even more, you might be retarded if you didn't know that
>>108520487Not C. C itself was all about being able to tell how it looks in assembly. So in a way C did that for "backwards compatibility" with assembly.In assembly this is an offset.0 = "no offset, just start reading from memory right here".
The variable of an array contains a pointer to that array. If you want to operate on one of the arrays values you do "array_pointer+offset ".Offset 0 means you get the first value.If you access myarray[x], "x" is that offset.The answer hence is that arrays start with 0 simply because thats how you access an array in memory.
>>108520533That's only true for C, maybe C++ and such. They have pointers.If your language does not have pointers, but have 0 as first element index, it's legacy.And it's not like all of them start with 0. Some start at 1. Python, right?
>>108520543>Python, right?Nope. I think u think of matlab
>>108520543haven't used it since college but matlab is 1 indexed
>>108520555that'll teach me to not update the thread before posting
>>108520312>99% of /g/ will fail this.grim
because positive numbers start with 0. if positive numbers would start with 1, arrays would be 1-based.
>>108520312Because arrays are cobbled onto address pointers, so the first element is an offset of 0 from the pointer that points to the beginning of the array.Now, it's not necessary to do it like that. The arrays I make in assembly store the length of the array in the first element, so all the values in the array are essentially 1 indexed, which makes iterating through the arrays in either direction trivial.
>>108520312>Why does the array index start with 0?What's the array?
>>108520662A series of tubes
>>108520720*A series of values
>>108520768Technically, a contiguous series of memory segments.
>>108520312Hindu interview phone question:>How do you perform the fabled Hindu Hadoken?99% of /g/ will fail this.
>>108520496In many countries, about 10% ethanol is added, not to mention impurities, detergents, stabilisers, and so on
>>108520487>Because C decided it starts at 0Nope, it was BCPL that decided it starts at 0 then B inherited this from BCPL then C inherited it from B. BCPL is also where C got its fall-through behavior in switch statements, pointer arithmetic, printf, and a variety of other quirks.
>>108520312Your question is poorly defined and it's premise is false in many languages, next question
>>108520482>>108520491>>108520647>>108520662>>108521105filtered>>108520533>>108520660correctActually embarrassing, this is an easy question.
>>108520312>>108521416kill yourself tranny, no one cares about this useless info anymore.
>>108521416You got filtered by Dijkstra's answer.