Accessing direct memory address and can we access directly any memory address?

int main(void)
{
int *a=6;
printf("%d",*a);
return 0;
}

in this code we are accessing direct some memory address let 6, we will get segmentation fault.Why?? And how can i access it without any error? Can i access memory address directly? Memory management is feature of processor or OS?


each time you load a program it keeps to itself a range of addresses(Address space) that belong to it to over simplify it think of it like from address let's say 1000 till 4000 your stack and heap resides means you can allocate memory only in that rage, refer to these addresses and these addresses alone. let's imagine a "what if" let's say we could actually access address 6 but in that location your OS actually have some super important data and by accident you write over that data. OS programmers were smart enough to not allow us accessing stuff we shouldn't.

链接地址: http://www.djcxy.com/p/31668.html

上一篇: 如何基准Swift代码执行?

下一篇: 访问直接内存地址,我们可以直接访问任何内存地址?