What happens in OS when we dereference a NULL pointer in C?

后端 未结 5 879
天涯浪人
天涯浪人 2020-11-27 02:56

Let\'s say there is a pointer and we initialize it with NULL.

int* ptr = NULL;
*ptr = 10;

Now , the program will crash since ptr

5条回答
  •  春和景丽
    2020-11-27 03:45

    I imagine that this is platform and compiler dependent. The NULL pointer could be implemented by using a NULL page, in which case you'd have a page fault, or it could be below the segment limit for an expand-down segment, in which case you'd have a segmentation fault.

    This is not a definitive answer, just my conjecture.

提交回复
热议问题