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

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -