[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


File: 1774879819663217.jpg (117 KB, 1080x1441)
117 KB
117 KB JPG
Google interview phone question:
>Why does the array index start with 0?
99% of /g/ will fail this.
>>
>>108520312
I look like that
>>
>>108520322 (checked)
You will never be a Korean woman.
>>
>>108520335
Mean
>>
File: 1748154761580.png (1.73 MB, 2048x1449)
1.73 MB
1.73 MB PNG
>>108520312
>>
I'm at a loss for words and I'm too embarrassed to google it
>>
>>108520312
I got one
>mechanic interview question:
>what are the chemical components of gasoline
most mechanics will fail this
>>
>>108520312
Because 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.
>>
>>108520312
Because Dijkstra said so.
https://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831.html
>>
>>108520470
Carbon 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
>>
>>108520487
Not 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.
>>
>>108520533
That'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
>>
>>108520543
haven't used it since college but matlab is 1 indexed
>>
>>108520555
that'll teach me to not update the thread before posting
>>
>>108520312
>99% of /g/ will fail this.
grim
>>
File: 1772985114029038.jpg (137 KB, 894x894)
137 KB
137 KB JPG
because positive numbers start with 0. if positive numbers would start with 1, arrays would be 1-based.
>>
>>108520312
Because 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?
>>
>>108520662
A series of tubes
>>
>>108520720
*A series of values
>>
>>108520768
Technically, a contiguous series of memory segments.
>>
>>108520312
Hindu interview phone question:
>How do you perform the fabled Hindu Hadoken?
99% of /g/ will fail this.
>>
>>108520496
In many countries, about 10% ethanol is added, not to mention impurities, detergents, stabilisers, and so on
>>
>>108520487
>Because C decided it starts at 0
Nope, 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.
>>
>>108520312
Your question is poorly defined and it's premise is false in many languages, next question
>>
File: GsjJxPPasAQL3ym.jpg (494 KB, 1440x1800)
494 KB
494 KB JPG
>>108520482
>>108520491
>>108520647
>>108520662
>>108521105
filtered
>>108520533
>>108520660
correct
Actually embarrassing, this is an easy question.
>>
>>108520312
>>108521416
kill yourself tranny, no one cares about this useless info anymore.
>>
>>108521416
You got filtered by Dijkstra's answer.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.