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?