Dark Hypernova
Science and Fiction

Today I Learned

Heap on Mac and Linux

#include <iostream>

int main() {

   double *a = new double[5];
   
   for(auto i = 0; i < 5; i++)
   {
     a[i] = i;
   }

   std::cout << a[-10] << std::endl;

}

This program runs on Mac without warning or error. However, it gives segmentation fault (core dump) error on ubuntu and cent os.

A Random #TIL# for You

By OctoMiao

Last updated