illegal memory access(非法内存访问)

来源:互联网 发布:搜狗输入法linux版 编辑:程序博客网 时间:2024/05/17 15:22

"illegal memory access" means that the process has accessed the memory address that does not belong to it.

 

When each process is executed, it must be allocated memory for it firstly. During the execution, the process can only access the memory that belongs to it. Otherwise, illegal memory access will occur.

 

But some developer may make some mistakes because of carelessness which results in "illegal memory access" programmatically.

 

For instance,

Int *p;

*p=10; L (将p指向的地址赋值为10,但并没有定义p指向的地址,所以10可能被赋值到任何地方,p为悬浮指针)

Point p is not initiated. Everything is possible , just like pointer p points to any memory address. That is to say, p may point to the memory address that does not belong to it at all.

 

When some modification is made on the code above, it will work.

Int *p;

Int x;

P=&x;

*p=10;

That's ok.

 

原创粉丝点击