Linux和Windows不一样吗》为什么我的代码运行和上面的结果不一样?而且delete就出错!
#include <iostream> #include "Coornidate.h" using namespace std; int main() { Coornidate* p = new Coornidate[3]; Coornidate coor[3]; coor[0].X = 11; coor[0].Y = 11; p->X = 10; p[0].Y = 11; p++; p->X = 20; p->Y = 21; // p[1].X = 3; // p[1].Y = 3; for(int i=0;i<3;i++) { cout<<p[i].X<<" : "<<p[i].Y<<" "<<"\n"; p--; } p++; // delete [] p; }
20 : 21 20 : 21 20 : 21
delete内存:
00e09000-00e3b000 rw-p 00000000 00:00 0 [heap]7f66fc000000-7f66fc021000 rw-p 00000000 00:00 0 7f66fc021000-7f6700000000 ---p 00000000 00:00 0 7f670095a000-7f6700970000 r-xp 00000000 103:08 1053774 /lib/x86_64-linux-gnu/libgcc_s.so.17f6700970000-7f6700b6f000 ---p 00016000 103:08 1053774 /lib/x86_64-linux-gnu/libgcc_s.so.17f6700b6f000-7f6700b70000 rw-p 00015000 103:08 1053774 /lib/x86_64-linux-gnu/libgcc_s.so.17f6700b70000-7f6700c78000 r-xp 00000000 103:08 1054128 /lib/x86_64-linux-gnu/libm-2.23.so7f6700c78000-7f6700e77000 ---p 00108000 103:08 1054128 /lib/x86_64-linux-gnu/libm-2.23.so7f6700e77000-7f6700e78000 r--p 00107000 103:08 1054128 /lib/x86_64-linux-gnu/libm-2.23.so7f6700e78000-7f6700e79000 rw-p 00108000 103:08 1054128 /lib/x86_64-linux-gnu/libm-2.23.so7f6700e79000-7f6701039000 r-xp 00000000 103:08 1054132 /lib/x86_64-linux-gnu/libc-2.23.so7f6701039000-7f6701239000 ---p 001c0000 103:08 1054132 /lib/x86_64-linux-gnu/libc-2.23.so7f6701239000-7f670123d000 r--p 001c0000 103:08 1054132 /lib/x86_64-linux-gnu/libc-2.23.so7f670123d000-7f670123f000 rw-p 001c4000 103:08 1054132 /lib/x86_64-linux-gnu/libc-2.23.so7f670123f000-7f6701243000 rw-p 00000000 00:00 0 7f6701243000-7f67013b5000 r-xp 00000000 103:08 1705995 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.217f67013b5000-7f67015b5000 ---p 00172000 103:08 1705995 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.217f67015b5000-7f67015bf000 r--p 00172000 103:08 1705995 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.217f67015bf000-7f67015c1000 rw-p 0017c000 103:08 1705995 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.217f67015c1000-7f67015c5000 rw-p 00000000 00:00 0 7f67015c5000-7f67015eb000 r-xp 00000000 103:08 1054130 /lib/x86_64-linux-gnu/ld-2.23.so7f67017b3000-7f67017b9000 rw-p 00000000 00:00 0 7f67017e9000-7f67017ea000 rw-p 00000000 00:00 0 7f67017ea000-7f67017eb000 r--p 00025000 103:08 1054130 /lib/x86_64-linux-gnu/ld-2.23.so7f67017eb000-7f67017ec000 rw-p 00026000 103:08 1054130 /lib/x86_64-linux-gnu/ld-2.23.so7f67017ec000-7f67017ed000 rw-p 00000000 00:00 0 7ffc32477000-7ffc32498000 rw-p 00000000 00:00 0 [stack]7ffc325cb000-7ffc325ce000 r--p 00000000 00:00 0 [vvar]7ffc325ce000-7ffc325d0000 r-xp 00000000 00:00 0 [vdso]ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]