c - what is "hanging reference" & "general protection fault"? -


i came across on net while studying memory leak related stuff.

int* function()  {     int arrays[10];       /* code here */     return &(arrays[0]);  } 

the author says above piece of code valid, memory returned reused next function call, same memory used 2 purposes. called "hanging reference" , can cause horribly intermittent faults, or old-fashioned "general protection fault".

it great if can explain "hanging reference" & "general protection fault"

i don't know if these official explanations hope gives better meaning example:

hanging reference: return statement returns reference (pointer) arrays. however, memory (or can be) removed after function closes, there refererence not pointing allocated memory, called hanging reference.

this can result in general protection fault. in general, memory not allocated should not written into. if try general protection fault can raised operating system.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -