Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- char * string = malloc(14);
- strcpy(string, "Hello World!\n");
- char * ptr = string;
- printf("%s is at %p\n", string, string);
- free(string);
- printf("%s is at %p\n", ptr, ptr);
- // char * newstring = malloc(5);
- // strncpy(newstring, " Bye", 5);
- strncpy(ptr, " Bye", 5);
- printf("%s is at %p\n", ptr, ptr);
- return 0;
- }
- /* This pleases me way more than it should
- *
- * Hello World!
- * is at 0x7ffae04006a0
- * Hello World!
- * is at 0x7ffae04006a0
- * Bye World!
- * is at 0x7ffae04006a0
- *
- *
- * Next thing I should try - two threads, does one use the other's freed memory
- * - start two processes, does one use the other's freed memory
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement