I just wanted to know if we can skip the segmentation fault at runtime and write something at memory location of NULL . As of now i believe its a very sacrosanct place and you cant do anything there. I tried a little piece of code.
#include<iostream>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int main()
{
int *p = NULL;
int z=6;
p= &z;
std::cout << "value of p is :" << *p;
p=NULL;
*p=5; // Will give segmentation fault as dereferencing of NULL is not allowed
std::cout << "value of p is :" << *p;
getch();
return 0;
}
I know dereferencing the NULL memory allocation is not possible and hence it cant be assigned any value . Doing so gives us segmentation fault. Just for an inquisitive nature, if we can cheat and write at NULL?
In a typical modern system, there is actually no memory mapped at virtual address 0. It’s simply not there at all. The CPU itself is what raises the segmentation fault when you try to write to address 0.
There is a physical address 0, but modern operating systems have virtual memory mapping that gives each process its own custom address space. That address space includes no mapping for virtual address 0.