What is “null pointer assignment error”?

后端 未结 5 1441
野趣味
野趣味 2021-02-04 09:33

One of job interview questions on C pointers here is the following: what is null pointer assignment error?

I\'ve googled for a while and don\'t see any reasonab

5条回答
  •  生来不讨喜
    2021-02-04 09:58

    I actually can not recall the source, but according to the source, this run time error is restricted to small and medium memory models being put into use by corresponding compiler. You see, as told before, the null pointer actually does not points to zero, in fact different compilers use different but fixed memory location to be used as null pointer.

    Lets consider the case of TC compiler, this compiler places four zero bytes at the bottom of the data segment and TC copyright notice. TC also uses DS:0000 location, bottom of the data segment as null pointers location. So, assigning a value to this null pointer, would actully change the four bytes and probably, mess up the copyright notice.

    Now, at the program termination, the four zeros and copyright banner are checked for any kind of alteration. If any alterations are found, it generates a Null Pointer Assignment error.

    So, I think its not just the null pointer, any pointer that gets wild, if tries to access some key areas, you are greeted with Null Pointer Assignment Error.

提交回复
热议问题