c++ - Deletion of reference underlying -


what happen reference if underlying variable whom referring got deleted?

for e.g. why below code giving 12 output checked both on gcc , msvc

int *x = new int(1); int& y = *x; delete x; x=null; int z = 12; y=z; cout<<"y = "<<y<<endl; 

accessing object memory has been deleted undefined behaviour, regardless of whether directly or through reference.

the fact code outputs 12 on gcc , msvc largely irrelevant: output 13, or 42, or potato , still standard-conformant.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -