Want to get first(1st) element in array

>want to get first(1st) element in array
>array[0]
wtf i hate programming now

Other urls found in this thread:

rbt.asia/g/thread/S55862311
rbt.asia/g/thread/S55813405
rbt.asia/g/thread/S55749009
en.wikipedia.org/wiki/Comparison_of_programming_languages_(array)#Array_system_cross-reference_list
twitter.com/SFWRedditImages

You've made this thread before

It's because they copied the C memes

/thread and OP is a fag

Thanks for the cool memes, OP

#define FIRST 0
array[FIRST]
DANKE

>mentally subtracting 1 every time makes my brain overheat

>why not x+1?
or maybe just x

>length of array ≠ offset of final element in array
what a joke

>the one and only advantage to 1-based indexing
what a joke

Heck, why even have 0? We don't need nothing right?

use lua then,it counts from 1

> Sup Forums BTFO
> how can Sup Forums even compete?
> will Sup Forums ever recover?
> Sup Forums will defend this
> protip: you can't
> what did he mean by this?
> really makes you think
Look mom, I posted it again!

It is OK. Everyone hates that at first. But if you end up doing a lot of programming in school (or as a hobby) then you get used to it. And starting at zero becomes natural.

I'm being sincere, I've only seen one user actually try to argue for 0-based indexing with examples. until you idiots learn to work together and educate me I'll continue posting it.

array[0] = *(array + 0)
OP is a fag

>array[0] = *(array + 0)
Is that a pointer or something?

Yes. array is a pointer to the first element of the array.

You're being an asshole about it OP. I understand your sentiment, but it's like asking why is the basic word size is 8 bits when a lot of shit was done with 5-bit baudot codes, or 6-lowercase-is-for-plebs-bit, and for a long time 7-bit ASCII was "enough", etc...
Nobody is shitposting about "lawlz, 7 days in a week, 7 bits in an ASCII code, 8-bits are for nigz"
Maybe try doing some of your own research.

it's pointer syntax
semantically it's: Position named "array" + 0 + sizeof(type)

Which is the main reason we index from 0
When arrays were just memory positions, it made sense.
These days it's mainly because it makes weird arithmetic things (e.g. multidimensional without fragmenting memory) easier

wot if you went past the array length with the pointer? like *(array + 99) when the array only contains 50 items?

>Maybe try doing some of your own research.
Why? You guys give me (You)s every time I post. I wouldn't get the same level of satisfaction.

rbt.asia/g/thread/S55862311
rbt.asia/g/thread/S55813405
rbt.asia/g/thread/S55749009

>When arrays were just memory positions, it made sense.
>were
Arrays are still just memory locations.

>2016
>not storing array items in random locations in memory
ishygddt

you'd get whatever garbage is stored at that address in memory

I think there are some very old languages that have an index that starts with 1

In general, random stuff, at least in C.
From garbage to trap to segfault anythin can happen, depending on memory layout, virtual memory manager, kernel and sometimes libc.

Usually (unless using C, or low level languages) the array type is some kind of abstraction over the memory location. Most of the time they have some bounds checking.
The [] operator is still used, but has slightly different semantics, so I wouldn't call it "just a location in memory" even if that's the underlying storage.

No, back in Fortran days, arrays started at 0 but people kept passing the pointer to functions as array[-1] so they could act like it was 1 indexed. You could still do that in C if you really want.

have a look user
en.wikipedia.org/wiki/Comparison_of_programming_languages_(array)#Array_system_cross-reference_list