Undefined behaviour, and why "it worked on my laptop"
When your C program breaks a rule — reads past an array, uses freed memory — the standard says the behaviour is undefined. Not "crashes". Not "prints garbage". Undefined: anything is allowed to happen, including working perfectly today and failing in the evaluation lab tomorrow.
That is why memory bugs are the hardest bugs in C. The symptom appears far from the cause, and it moves.
Here are the five you will actually meet.
1. Use after free (dangling pointer)
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int *p = malloc(sizeof(int));
if (p == NULL) return 1;