fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5.  
  6. size_t petabyte = 1024LL * 1024LL * 1024LL * 1024LL * 1024LL; // 10^15
  7. printf("petabyte %zd \n", petabyte);
  8. printf("sizeof(size_t) = %ld \n", sizeof(size_t));
  9.  
  10. volatile char *ptr = (volatile char *)malloc(petabyte);
  11. printf("malloc() - success, ptr = %p \n", ptr);
  12.  
  13. ptr[petabyte - 1LL] = 10;
  14. printf("ptr[petabyte - 1] = 10; - success \n");
  15.  
  16. printf("ptr[petabyte - 1] = %d \n", (int)(ptr[petabyte - 1LL]));
  17.  
  18. //free((void*)ptr); // why the error is here?
  19. //printf("free() - success \n");
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 2244KB
stdin
Standard input is empty
stdout
petabyte 0 
sizeof(size_t) = 4 
malloc() - success, ptr = 0x9818008 
ptr[petabyte - 1] = 10; - success 
ptr[petabyte - 1] = 10