Want to get first element in an array

>want to get first element in an array
>array[0]
>programmingfags will defend this

Other urls found in this thread:

cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
twitter.com/SFWRedditImages

it makes perfect sense for C arrays

go back to lua pleb.

This. Learn C and it will make sense.

Or use the lua[1] model and write C modules for it. Openresty has power boi.

>be a normal human
>want to get the first element
>have to do the complicated mental arithmetic of adding 1
yeah I might go back to lua sempai

of all the things to bitch about

array+0

Do you even know what the subscript "[ ]" does?

pointers and shit sempai, I'm just wondering why I have to put up with this bullshit when the compiler or interpreter could take care of it instead.

learn assembly

>complicated mental arithmetic
I guess programming just isn't for you

2^0
is why. any questions?

yes

like what dad. ask away.

I'm not going to tell you what the question is, I'm just letting you know that I have one.

i think you mean you have [0] question.

>1 is the first ordinal
>this is what non-math-literate brainlets actually believe

New Document 1

>copy file 49 times
>50 files
>last one is called Document(49)
>mathematicians will defend this

>want to make first post on Sup Forums
>PHHHBBBPHBPHV *PLOP* *SQUIRT* PHHHTTPHHTTssssssssss
>summerfags will defend this

>this is what non-math-literate brainlets actually believe
this.

0,1
1,2

Which is best?

the 0th one.

Pascal is baby tier language and uses 1-indexed arrays. So go use that

nofap = high test = beard growth?

>using numbers to index location
>there are 10 decimal numbers 0-9
>wants to start with second number
Why would you skip one number, are you retarded?
>Oh lets index this using letters, lets start with B

except A is the FIRST letter in the alphabet, 0 is the 0th.

actually in Pascal you can index from whatever you want, be it 0, 1, 555 or even 'a' or 'k'

Nope. 0 is literally the first number. "0th" doesn't mean anything its like saying Ath

0 is the 1st, 0 is a number.

then explain why we count things starting at 1? wow it's almost like 0 is a number that shows there is no value or something.

Wtf, mate? Then A has to be Ath character im alphabet, right?

counting is adding 1 to the previous number, so technically you start at 0.

Well said

listen man I know counting is a complicated thing, but think REALLY hard for a moment. A is the FIRST letter of the alphabet. B is the second. when we get all the way to Z, that's the TWENTY SIXTH. now if I ask you how many letters are in the alphabet what do you say? THAT'S RIGHT user, THERE ARE 26! BECAUSE HUMANS COUNT NUMBERS STARTING AT 1!

Zero is a value.

I'm not denying that, but counting from 0 literally goes against all human logic.

Refer to

Just give it up idiot.

0 is a number
0 or 1 index, are both the same just take it for granite or use a babby-tier 1-index language if you insist.

Look ass hat, itso not about the logic, it's about using the most bang for your buck on a computer, back when computers were old and shitty. You map 0 because the Arabic numerals are 0-9 and it would be wasteful as fuck to only use 1-9. 10 adds an extra digit, aka more memory.

Why do you think hex was invented? So that we can use more info per digit. Learn some computer architecture before you start spewing utter bullshit. These gpu threads are cancerous enough without you spreading retard. At least I can understand the shills getting paid to shill, but you're just retarded.

Ok so if you can't count 0 as a number, then what do you do when you have 10 things?
>oy, that ends in a 0, m8. Cant have that, its not a number! Must be 11 things there then.
What is this, ancient times where zero was avoided and feared?

matlab is nice

Hmm I wonder if you sperg out whenever you read 00:00 on a clock

Also, angle 0 == angle 360 in a circle. MIND BLOWN.

>~=

> when you typed 0th as a sarcastic joke to prove op's idiocy, op defends it and user gets its.
> shit tier to the 0th
> grats to the 1st

not you, I meant

Why is this addressed to me? None of it is relevant to my post.

>not 0[array]

Were you dropped on your head as a kid?

apologies

are you dumb?

so your response to me asking "if it's 2016 and we don't care about file size so why do we count from 0" is "because history"
That's not a valid reason sempai

The worst part is that programmingfags will defend this for arrays whose type don't guarantee at least one item.

C will rape you for it, and even Haskell fucks it up.

how should it be done user?

Clearly not as dumb as the one who can't even add or subract a 1 from his indecies every now and again. Pretty sad, fampie.

>> because adding one is hard...
Is not a valid reason to change every programming language and thereby every program ever written to add one to every array, senpai.

high level programming languages should take care of it when being compiled / interpreted. simple as that. it's all pointers and shit so 0 based makes sense for computers, but why not make it simpler when writing code?

How else would you do it, faggot?

>$CURRENT_YEAR
>we don't care about file size
Well-crafted; have a (You).

It makes looping through the entire array simple as fuck though.
for (i=0; i < length; i++)

>angle 0 == angle 360 in a circle.
Yeah, same with the time though. 0:00 is the same as 24:00, if that existed.
The idea is that you can use the modulo operation, so the angle modulo 360 would give you 0 if it's 360, 1 if 361, etc. Or if you say "Yeah I've been awake for 72 hours" that's exactly the same as saying "I've been awake for 0 hours" because 72 modulo 24 is 0.

When you go jogging, do you start counting at 1? No. You count 0.25 miles, 0.5 miles, ..., 1 mile, ..., 2 miles.

Well, have fun building the compiler. Just make sure ithat can read 0 based arrays as a legacy setting. Otherwise big companies like IBM can't use it.

nice low level language kid, that's not what I'm talking about.

literally look one post above yours.

fair point, but when humans count something they generally start at 1.

literally doesn't change file size if the compiler takes care of it

Yeah i learned all of this in Grade 2

but started applying and getting in touch with it writing watchface apps for Android Wear

>Java ODBC

Array points to the start of the memory, and array[0] is an alias to array+0.

but distance is a continuous system. you haven't ran until you've taken your first (1) step, but you can still have a nonempty list with element 0

&array[0]

kek

this
/thread

I'M AWARE SEMPAI, THE COMPILER CAN JUST TAKE CARE OF IT.

was just about to say this, an empty list would have length of 0. a list with 1 element would have length of 1 so why would it be element 0?

Starting from 0 or 1 is a religious question

What do you mean? That the compiler should translate array[1] to array+1-1? That would be way to confusing.

because *(array + 0)

Array name is a reference to the memory location in which the first element of the array is stored. Array[0] means that exact memory location. Array[1] is the memory address of the array + space that an item of the array will take, meaning the address of the second item.

cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html

>nice low level language kid, that's not what I'm talking about.
Oh ok, this is just a thread for script kiddies to complain then. Well, I'm out. Got more important things to do that babysit highschool level "coders."

Because then it doesn't make sense when you actually want to do something the way it is being interpreted. Like if you were to access the actual memory, it wouldn't be what you wrote in.

Write some code for me right now fuckface

You have an array, you need the first element only, not to loop over the whole thing or anything like that. What do you do?

Then write the compiler fampai!! Or else stop bitching for someone to move mountains so that you can avoid a "problem" that is just your personal preference

you start at 0. The first element that comes is one more from the empty state, 1.

mfw some people will actually defend lua style array indexing when not even lua thinks its right anymore.

do you know how complicated compilers are? it makes no difference.
is this a joke? do you mean with 0 based or 1 based? either way it's literally just array[0] or array[1]

for(int i =1;i

Then what the fuck is the point of this thread? You fucking retard

I'm wondering why you people are so autistic that you refuse to make a change that will do nothing but make programming easier.

I'm not saying it would be complicated to the compiler, it would be complicated in my mind, because when programming, I am always imagining what is happening memory-wise.
Also, imagine you want to access the array and you want values that excede the array length to be wrapped around, in C, you just say array[ index % length ] while if it started in 1, you would have to do array[ (index - 1) % length + 1]

sometimes it makes the mathematics easier, and i like that

Please stop trolling. It's been explained why 0 is the correct number to start from in C and you're just ignoring it.

finally someone has a proper argument, if you're thinking about it memory-wise then you probably use a low level language which isn't what I'm talking about. regarding the modulo thing idk desu, will have to think about that.

in what situations?

It's because of who writes compilers. People don't write compilers for students, they write them for enterprise so they can make money. If IBM buys 100,000 copies of a compiler, then that company just made a million dollars. But compilers must support legacy ie. 0 based, because that is 100% of IBMs code. IBM isn't going to rewrite 1million lines of code just to use 1 based indexing later. Therefore no one will bother to write it.

But if you want to, go the fuck ahead and stop complaining.

I've been writing code for years you wanna-be faggot

I'm still waiting for you to write code, go on you "genius"

Quick, write a function that averages two integers.

I think you should really make a table with all the situations in which it is easier to program with index 1, then index 0, then shove it up your ass. The only people who complain about this shit is people who are just learning programming and feel it's counter intuitive, YOU AREN'T BORN KNOWING EVERYThiNG, GET OVER IT.

No, shut the fuck up

You made fun of doing array[0] like you can't believe people do this, so you better write me some code that's "better" right now or else shut your fucking mouth

and the autists come out, like clockwork.

>> ITT: freshman cs student vs. A lot of fish who can't resist the most obvious bait

[CODE]
int average(int a, int b)
{
return ((long)a+b)/2;
}
[/CODE]

>averaging ints meme
Quick, takes yours.

u fucked up hard son.

As with 99% of common programming concepts. C is a tad more complex, but everything will make more sense if you know it.

def average(a, b):
return int((a+b)/2)