I just realised that int Array[] = new Array[99]; doesn't create 0 to 99 different positions (100 in total) but rather creates only 99 different positions that start at 0 and to go to 98.
I've been "programing" for almost a year now.
>>27450741
mega original the comment
>>27450784
About you, maybe. Lol.
>>27450784
I don't care. I need to put my day into words so I can work on my communication skills.
And besides, a single (you) was worth it.
Which language? c++? If c++, then that might have actually "worked" (it's undefined behavior but heap alignment might have forced power-of-2 elements to be allocated.)
>>27450848
er, I mean multiple of 2 elements (if int is 4 bytes, on 64 bit, you might get that 100th element allocated)
>>27450819
My bf disagrees
I am bi male before you ask for tits.
He also annoys me with his programming bullshit which I don't give a fuck about.
He also programs stupid shit that doesn't do anything worth shit.
It doesn't matter, eventually all lower level programmers will be replaced by poo in loos
>>27450848
Java.
Ah opps, I meant i"nt[] Array" and not "int Array[]"
>>27450741
all the memory you use in programs is virtual so no matter what an array could be split up in lots of different places in the computer
just focus on algorithmic learning how programs actually work won't help you in anyway
>>27450914
... ok ... so you've never gotten an ArrayOutOfBoundsException? Do you just allocate $what_I_think + $random_number??
>>27450741
wat
How did you not know that? It's not that big of a deal though I'm just surprised you have been doing it for that long and never noticed.
>OP fell for the Array meme
Don't worry OP, it's a first year CS mistake. Also watch out for the difference between assignment and equality operators
>>27450914
Java: saving programmers from themselves since 1996
>>27450741
>I've been "programing" for almost a year now.
Thats why lower lvl languages that do not allow to do things like "for i in array" are better.
If you were forced to create multidimensional array in C and use nested loops to print values, you would figure it out at first exercise.
>>27451105
mean
*are better for learning basic programming
>>27451105
Actually, sometimes, sadly not:
$ echo 'int main() { int **array, i, j; array = calloc(sizeof(int *), 3); for(i=0; i<4; i++) array[i] = calloc(sizeof(int), 3); for(i=0; i<4; i++) for(j=0; j<4; j++) array[i][j] = i*10+j; for(i=0; i<4; i++) for(j=0; j<4; j++) printf("array[%i][%i] = %i\n", i, j, array[i][j]); return 0;}' | gcc -x c -std=c89 -o test -
$ ./test
array[0][0] = 0
array[0][1] = 1
array[0][2] = 2
array[0][3] = 3
array[1][0] = 10
array[1][1] = 11
array[1][2] = 12
array[1][3] = 13
array[2][0] = 20
array[2][1] = 21
array[2][2] = 22
array[2][3] = 23
array[3][0] = 30
array[3][1] = 31
array[3][2] = 32
array[3][3] = 33
(Note the improperly sized calloc)
>>27451222
valgrind catches it, but people don't often use it :(
$ valgrind ./test
[snip]
==28403== Invalid write of size 8
==28403== at 0x4005C6: main (in /home/no/test)
==28403== Address 0x51fc058 is 0 bytes after a block of size 24 alloc'd
==28403== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28403== by 0x400594: main (in /home/no/test)
==28403==
==28403== Invalid write of size 4
==28403== at 0x40061D: main (in /home/no/test)
==28403== Address 0x51fc0ac is 0 bytes after a block of size 12 alloc'd
==28403== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28403== by 0x4005C5: main (in /home/no/test)
==28403==
==28403== Invalid read of size 8
==28403== at 0x4005F9: main (in /home/no/test)
==28403== Address 0x51fc058 is 0 bytes after a block of size 24 alloc'd
==28403== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28403== by 0x400594: main (in /home/no/test)
==28403==
array[0][0] = 0
array[0][1] = 1
array[0][2] = 2
==28403== Invalid read of size 4
==28403== at 0x400669: main (in /home/no/test)
==28403== Address 0x51fc0ac is 0 bytes after a block of size 12 alloc'd
==28403== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28403== by 0x4005C5: main (in /home/no/test)
==28403==
array[0][3] = 3
array[1][0] = 10
array[1][1] = 11
array[1][2] = 12
array[1][3] = 13
array[2][0] = 20
array[2][1] = 21
array[2][2] = 22
array[2][3] = 23
==28403== Invalid read of size 8
==28403== at 0x400659: main (in /home/no/test)
==28403== Address 0x51fc058 is 0 bytes after a block of size 24 alloc'd
==28403== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28403== by 0x400594: main (in /home/no/test)
==28403==
array[3][0] = 30
array[3][1] = 31
array[3][2] = 32
array[3][3] = 33