[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

>want to select the first element in an array >array[0]

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 33
Thread images: 1

File: facebook_zuck.jpg (23KB, 384x384px) Image search: [Google]
facebook_zuck.jpg
23KB, 384x384px
>want to select the first element in an array
>array[0]
wtf i hate programming now
>>
redefine the index.....oh your language doesn't support that...
>>
>not using linked lists
are you even trying?
>>
>>55749009
use LUA
>>
Just put some junk on the 0th position of every array.
>>
>>55751158
>open source code
>ctrl-F
>DONG
>1 of 30,000
anon get in my office
>>
>>55749009
>tfw argv[0] in C is reserved for the programs name

Literally why?
>>
index = 1 lel
>>
>>55749009
#define get(arr, i) *((arr) + (i) - 1)
>>
>>55751421
For the same reason
 false == 0 
and
 5==true 
>>
>not using Hasklel
>>
for (int count = 0; count < 10; count++)

Does the thing 10 times, and doesn't need the extra symbol for <=.

What pissed me off more than anything are the languages that decided to index from zero. I have to use Matlab for work and I always have to mentally reset before using C or Python.
>>
>>55751421
>implying the name of the program isn't the first argument you're giving to stdin
>implying the rest of argc aren't your actual arguments
ur dumb anon
>>
>>55751603
For me it goes the other way, I always index from 0 and matlab is pissing me off with the out of bounds errors.
>>
>>55751500
Prelude> [1,2,3] !! 1
2
>>
>>55749009
array[0] doesn't literally mean "the first element of array", it's just the usual interpretation, but it really is equivalent to *(array+0), generalized to array[n] === *(array+n).
>>
>>55749009
>look mom, I posted it again! xD
Sage and hide.
>>
>>55749009
It makes more sense when you start using pointers since *(array + 0) == *array.
>>
>>55751776
>>55751603
> use OCTAVE at home, MATLAB at uni, Python at work
REEEEEE
>>
>>55752517
wew
at least drop octave, how can you handle 3 types of syntax at once?
>>
>>55749009
OP is a faggot
>>
>>55752558
> 3 types
HAHAHAHA
If only.
> MATLAB module at uni
> LabVIEW module at uni
> Simulink module at uni
> just started using *NIX system for first time ever
> Python at work
> helping flatmate learn C++
> fucking around with brainfuck in spare time
And that's just this semester.
>>
>arrays
>2016

Just use lists:
>muhList.first();
>>
>>55752637
>brainfuck
waste of time dude
>>
>>55752932
It was fun to screw around with.
>>
>>55749009

#DEFINE FIRST 0

You can shape C anyway you want. Even in retarded ways.
>>
>>55752972
#define 0 1
>>
>>55749009
>doing this
>ever

Unless you're still learning then you should stop programming. I hear McDonald's is hiring.
>>
>>55749009
int arr[3] = {9,11,13};

C doesn't have first class arrays, they are you pointers
assert(*arr = 9);

Since a pointer is a direction of memory and the array has regular size for each slot, you can take the offset of the slot you want
assert(*(arr + 1) = 11);

Which explains why the ``array notation'' is the way it is.
assert( arr[0] = *arr ) // 0 offset is the first element


assert( arr[1] = *(arr +1) ) // offset the second element


tl;dr: array notation is about offsets, no elements order
>>
0 index is just easier to calculate.
I sometimes write in a 1 indexed scripting language and I just add one to everything and it gets unreadable.

Make wrapper functions so you get errors when you select out of scope and accept that certain things just makes more sense.
There are several things about C that is really bad, but the indexing is not one of them.
>>
>>55749009
Kys
>>
$first = current($arr);

>muh PHP
>>
>>55749009
kys
Thread posts: 33
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.