c++ - Shows an error if the pointer variable being displayed is changed -


i high school student learning c++.so while doing pointers came across problem,

first pointer programme

when try display value @ y,it shows:terminal window

the value of x displayed properly,but after write *y *(x+1),it works fine

enter image description here

can 1 please explain why getting segmentation fault?

despite screenshots show,all code compiled perfectly.

y points unallocated memory, dereferencing undefined behaviour. need point @ valid memory, either allocating dynamically, or taking address of valid variable, did x.


Comments

Popular posts from this blog

c# - How can I have the VS Debugger break in the correct location for exceptions thrown in Async methods in a Console App? -

php - Issues outputting data after prepared statement with loops -

javascript - How to pass a property by reference -