I've tried the following code.But it is always crashing. Why? I didn't even change the content of address 0. Compiled on mingw32-g++
#include<iostream>
int main(){
int* p=0;
std::cout<<*p;
}
I've tried the following code.But it is always crashing. Why? I didn't even change the content of address 0. Compiled on mingw32-g++
#include<iostream>
int main(){
int* p=0;
std::cout<<*p;
}
Dereferencing a null pointer gives undefined behavior.
In a fairly typical case, there's really nothing there. For example, on an x86 in protected mode, you typically set up some page table entries for the beginning of memory that say nothing is present there, so any attempt at reading or writing that address will result in a page fault (e.g., both Windows and Linux do this).