|
|
p1[I].delete to free resources. |
|
delete p1 or if I should delete the arrays. delete[] first |
|
7f27a0b00000-7f27a0c6d000 r-xp 00000000 08:02 2211848 /lib64/libc-2.11.3.so 7f27a0c6d000-7f27a0e6d000 ---p 0016d000 08:02 2211848 /lib64/libc-2.11.3.so 7f27a0e6d000-7f27a0e71000 r--p 0016d000 08:02 2211848 /lib64/libc-2.11.3.so 7f27a0e71000-7f27a0e72000 rw-p 00171000 08:02 2211848 /lib64/libc-2.11.3.so 7f27a0e72000-7f27a0e77000 rw-p 00000000 00:00 0 7f27a0e78000-7f27a0e8d000 r-xp 00000000 08:02 2211866 /lib64/libgcc_s.so.1 7f27a0e8d000-7f27a108c000 ---p 00015000 08:02 2211866 /lib64/libgcc_s.so.1 7f27a108c000-7f27a108d000 r--p 00014000 08:02 2211866 /lib64/libgcc_s.so.1 7f27a108d000-7f27a108e000 rw-p 00015000 08:02 2211866 /lib64/libgcc_s.so.1 7f27a1090000-7f27a10eb000 r-xp 00000000 08:02 2211856 /lib64/libm-2.11.3.so 7f27a10eb000-7f27a12ea000 ---p 0005b000 08:02 2211856 /lib64/libm-2.11.3.so 7f27a12ea000-7f27a12eb000 r--p 0005a000 08:02 2211856 /lib64/libm-2.11.3.so 7f27a12eb000-7f27a1309000 rw-p 0005b000 08:02 2211856 /lib64/libm-2.11.3.so 7f27a1310000-7f27a13f8000 r-xp 00000000 08:02 48187287 /usr/lib64/libstdc++.so.6.0.17 7f27a13f8000-7f27a15f7000 ---p 000e8000 08:02 48187287 /usr/lib64/libstdc++.so.6.0.17 7f27a15f7000-7f27a15ff000 r--p 000e7000 08:02 48187287 /usr/lib64/libstdc++.so.6.0.17 7f27a15ff000-7f27a1601000 rw-p 000ef000 08:02 48187287 /usr/lib64/libstdc++.so.6.0.17 7f27a1601000-7f27a1616000 rw-p 00000000 00:00 0 7f27a1618000-7f27a1637000 r-xp 00000000 08:02 2212125 /lib64/ld-2.11.3.so 7f27a17f3000-7f27a17f8000 rw-p 00000000 00:00 0 7f27a1834000-7f27a1836000 rw-p 00000000 00:00 0 7f27a1836000-7f27a1837000 r--p 0001e000 08:02 2212125 /lib64/ld-2.11.3.so 7f27a1837000-7f27a1838000 rw-p 0001f000 08:02 2212125 /lib64/ld-2.11.3.so 7f27a1838000-7f27a1839000 rw-p 00000000 00:00 0 7fff51ede000-7fff51eff000 rw-p 00000000 00:00 0 [stack] 7fff51f98000-7fff51f99000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] 4197661 0 -1587542592 32551 6303808 0 1374671248 32767 4196816 0 Aborted shilaly@linux2:~/113/Lab4/second> |
|
|
Memory Space
Stack (Where program is located):
n -> {1,2,4,8,16,32,64,128,256,512}
Heap (Random memory you can allocate):
first -> int[10]
second -> int[10]
After your program runs (and crashes):
Stack (Where program is located):
first -> n -> {1,2,4,8,16,32,64,128,256,512} <- p1 (last value)
Heap (Random memory you can allocate):
int[10]
int[10]
(Orphaned memory)
Some Other Memory:
second -> p2 -> ???
|
|
|
|
|
new int[10]{...}.delete[] first because I changed that in the beginning and it's not on the free store. |
|
| ...it's required to use pointers... |
first[I] or *(first + I) if you wanted.| No wonder you thought I was silly.. |
| ...I've had pointers pointing to pointers? |
p1 = first, the memory address first holds is copied to p1. So they point to the same location, but not to each other. |
|
|
|
error: cannot convert â<brace-enclosed initializer list>â to âintâ in assignment |
|
|
arr[I] will be accessing the array at that index. So arr[3] is out of bounds.int I = {1, 2, 3};.you'd have to use a for loop to assign initial values. |