What prevents a computer from growing into chaos!
Modern processors have a mode of operation called protected mode with virtual memory - a regular program (process) runs in the so-called user mode and sees a memory space that is different from other currently running processes. The operating system then ensures that all such abnormal behavior is contained in one of these processes - although it is likely that such access will fail, it will only be contained in this process.
This was not true in older versions of Windows - while Windows 3 could use x86 protected mode, it ran all programs with the same privilege level - there the scary Blue Screen of Death could take the whole system down:

As for the part that
My tutorial assumes that the pointer variable still contains the address for the previously allocated memory, even after free () was called on it - suppose I used malloc () earlier.
This is actually not the case. The C standard states that after calling free on a pointer, the value of the pointer itself becomes undefined. It may still point to the same address in your implementation, but all bets are disabled. The following program may even crash on any platform:
void *ptr = malloc(42); free(ptr);
As the C standard says at 6.2.4p2
The pointer value becomes undefined when the object it points to (or has just passed) reaches the end of its life.
And Appendix J.2. Undefined behavior :
The value of a pointer to an object whose lifetime is used (6.2.4) is used.
One possible behavior can be caused by the compiler , knowing that the value is not required after free . Thus, if ptr in the above code was stored in a register, the compiler is free to overwrite the value for some code between them, and then the ptr variable could behave just like it was an uninitialized value by the time it was used in if .
Using a pointer whose value is indefinite will result in different related behaviors, such as confirmed here . The compiler does not have to generate the value you expect, it just has to conform to the standard.
In any case, the book is true that you should not use ptr after free(ptr) until you set a new value for it, it’s just that the specific example in the book is misleading since it’s just one of many possible results, as is usually the case for Undefined behavior in C.