-
Pointer's
Hello, here's the code
Code:
#include <iostream.h>
int main()
{
int x;
int *ptr = new int;
ptr=&x;
cin>>x;
cout<<*ptr;
delete ptr;
return 0;
}
I get the following error's when executing. 12 is my input.
Code:
12
12Exiting due to signal SIGSEGV
Page fault at eip=000057c4, error=0006
eax=000be93c ebx=000be938 ecx=000be800 edx=000be93c esi=00000054 edi=0003e960
ebp=000be8e8 esp=000be8dc program=C:\DJGPP\WTF\POINTER.EXE
cs: sel=00a7 base=8563a000 limit=ffb13fff
ds: sel=00b7 base=8563a000 limit=ffb13fff
es: sel=00b7 base=8563a000 limit=ffb13fff
fs: sel=0087 base=0000c220 limit=0000ffff
gs: sel=00c7 base=00000000 limit=0010ffff
ss: sel=00b7 base=8563a000 limit=ffb13fff
App stack: [000be960..0003e960] Exceptn stack: [0003e8bc..0003c97c]
Call frame traceback EIPs:
0x000057c4
0x0000f941
0x00001633
0x00005188
I know the error arn't code, i just wanted to keep it seperate.
My compiler is djgpp.
Any help would be much appreaciated.
-
you're right about the code... it's fine...
i see you're using djgpp compiler.....i am not a big fan of it.....
seams like the compiler has a conflict in allocating memory between the stack and the heap......
that's what i am sensing out.....
i suggest a different compiler or maybe try installing this one all over again...
Regards,
matheo917
-
If you point ptr to x, then you don't need to allocate space for ptr.
Code:
#include <iostream.h>
int main()
{
int x;
int *ptr;
ptr=&x;
cin>>x;
cout<<*ptr;
return 0;
}
If you want to use dynamic allocation, then you don't need x.
Code:
#include <iostream.h>
int main()
{
int *ptr = new int;
cin>>*ptr;
cout<<*ptr;
delete ptr;
return 0;
}
-
ahh i think i see.
Thank's swoopy, i jotted that down.