Quote (Eep @ Aug 30 2012 07:08pm)
my biggest issue is when I stop getting compiler errors, the website keeps telling me I allocated the wrong number of elements. Like I did 100 fucking loops and I am pretty sure I understand how arrays work by the end of cs1250.
Code
int *ip_arr[100];
int *a = new int[100];
for (int i = 0; i < 100; i++)
{
a[i] = -1;
ip_arr[i] = a+i;
}
is this not filling every (100) elements up?
this website is like a shitty person who tells you to make something and then bitches when you do exactly as they say.
This may be completely incorrect, but when you do
ip_arr[i] = a+i;
you're directly adding 0-99 to a memory location, correct? This is entirely neglecting the fact that integers are going to take up a larger space, right? So in reality it should be something like:
ip_arr[i] = a+(i*[insert memory size of your data type here]);
Normally using the syntax of arrays, the computer does this for you since it knows what data type your array is, so you can do things like myArray[a+i], but since you're adding directly to a memory location you have to factor in the size between each element according to the data type...?
If I'm wrong in my understanding of this please tell me, I'm new at this and would be happy to learn.