The following code prints all the numbers between 1 and 300. How come it does not throw throw a segmentation fault?
Compiled with:gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
Also this is now different from malloc(0) actually works?
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int *pi = (int *)malloc(1);
int i = 0;
for(i = 0;i < 300;i++) {
*(pi + i) = i + 1;
}
for (i=0;i < 300;i++) {
printf("%d\n", *(pi + i));
}
return 0;
}