help! i keep getting error Im using myprogramming lab,
the problem is this:
The variables arr1 and arr2 have been declared as pointers to integers. An array of 10 elements has been allocated, its pointer assigned to arr1, and the elements initialized to some values. Allocate an array of 20 elements, assign its pointer to arr2, copy the 10 elements from arr1 to the first 10 elements of arr2, and initialize the remander of the elements of arr2 to 0.
here is my code:
1 main() {
2 int *arr1, *arr2;
3
4 for(int i = 0; i < 20; i++)
5 {
6 arr2[i] = new int(i);
7 if(i < 10)
8 {
9 arr2[i] = arr1[i];
10 }
11 else
12 {
13 arr2[i] = 0;
14 }
15 }
Line 6 accesses the int at memory address arr2+i, ut what is arr2?? It then tries to assign an integer pointer that points to an integer with a value of i.
Line 9 is also accessing nonexistant memory both before and after the = sign.
And so is line 13.
so is line six the problem? i messed with that line so much i declared it but that was not it. I even wrote it with "*" in the begging but nothing still keeps getting me the same error. i know the other lines might be right. How can i fix it?