What is “null pointer assignment error”?

后端 未结 5 1440
野趣味
野趣味 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 10:06

    There are many scenarios where you can see problems. But the key thing is, you did not allocate the memory correctly. The following code would produce Null pointer assignment error message after you run the program. Note: It will compile correctly.

    void CopyMessage(char *p)
    {
        strcpy(p, "welcome");
    }
    
    void main()
    {
       char *src;
       CopyMessage(src);
    }
    

提交回复
热议问题