Hello, once again :) today is devoted to the pointers lesson! Now I have compiled everything successfully on the lesson so far except for the functionhere is what I have so far that compiles.Code:free(ptr);
but when I run the program I get thisCode:#include <stdio.h>
#include <stdlib.h>
main()
{
int x,*p=malloc(sizeof(*p));
p=&x;
printf("Enter a value for x:");
scanf("%d",&x);
printf("this is the output of *p:%d\n",*p);
free(p);
getchar();
}
Did I make a mistake? or am I missing libraries?Code:beatzz@AMD2500:~/c$ gcc -o pointers pointers.c
beatzz@AMD2500:~/c$ ./pointers
Enter a value for x:3
this is the output of *p:3
*** glibc detected *** ./pointers: free(): invalid pointer: 0xbfb8e150 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb7e16a85]
/lib/tls/i686/cmov/libc.so.6(cfree+0x90)[0xb7e1a4f0]
./pointers[0x80484a9]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe0)[0xb7dc1450]
./pointers[0x80483e1]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:01 3801091 /home/beatzz/c/pointers
08049000-0804a000 rw-p 00000000 08:01 3801091 /home/beatzz/c/pointers
0804a000-0806b000 rw-p 0804a000 00:00 0 [heap]
b7c00000-b7c21000 rw-p b7c00000 00:00 0
b7c21000-b7d00000 ---p b7c21000 00:00 0
b7daa000-b7dab000 rw-p b7daa000 00:00 0
b7dab000-b7ef4000 r-xp 00000000 08:01 12289040 /lib/tls/i686/cmov/libc-2.7.so
b7ef4000-b7ef5000 r--p 00149000 08:01 12289040 /lib/tls/i686/cmov/libc-2.7.so
b7ef5000-b7ef7000 rw-p 0014a000 08:01 12289040 /lib/tls/i686/cmov/libc-2.7.so
b7ef7000-b7efa000 rw-p b7ef7000 00:00 0
b7efd000-b7f07000 r-xp 00000000 08:01 12271638 /lib/libgcc_s.so.1
b7f07000-b7f08000 rw-p 0000a000 08:01 12271638 /lib/libgcc_s.so.1
b7f08000-b7f0c000 rw-p b7f08000 00:00 0
b7f0c000-b7f0d000 r-xp b7f0c000 00:00 0 [vdso]
b7f0d000-b7f27000 r-xp 00000000 08:01 12271629 /lib/ld-2.7.so
b7f27000-b7f29000 rw-p 00019000 08:01 12271629 /lib/ld-2.7.so
bfb7b000-bfb90000 rw-p bffeb000 00:00 0 [stack]
Aborted

