I wrote the code and tested, it is crashing. Code snapshot:
#include<stdio.h> #include<stdlib.h> int main() { int *ptr = malloc(sizeof(int)*5); free(ptr+1); return 0; }
int main() { int *ptr; ptr = (int*)malloc(sizeof(int)*5); /* malloc returns void pointer you need to typecast */ free(ptr); return 0; }