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,
when try display value @ y,it shows:
the value of x displayed properly,but after write *y *(x+1),it works fine
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
Post a Comment