fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int argc, char const *argv[]){
  6. char *char_ptr1, *char_ptr2;
  7. int *int_ptr;
  8. int mem_size;
  9.  
  10. mem_size = 1;
  11. printf("\t[+] allocation %d bytes of memory on the heap for char_ptr1\n", mem_size);
  12. char_ptr1 = (char *) malloc(mem_size);
  13. mem_size = 2;
  14. printf("\t[+] allocation %d bytes of memory on the heap for char_ptr2\n", mem_size);
  15. char_ptr2 = (char *) malloc(mem_size);
  16. strcpy(char_ptr1, "This is first memory is located on the heap");
  17. strcpy(char_ptr2, "This is second memory is located on the heap");
  18. printf("char_ptr (%p) --> '%s'\n",char_ptr1,char_ptr1);
  19. printf("char_ptr (%p) --> '%s'\n",char_ptr2,char_ptr2);
  20.  
  21. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
	[+] allocation 1 bytes of memory on the heap for char_ptr1
	[+] allocation 2 bytes of memory on the heap for char_ptr2
char_ptr (0x5621bbcbcc30) --> 'This is first memory is located on the heap'
char_ptr (0x5621bbcbcc50) --> 'on the heap'