Why am I getting segfault when changing the signature of main?

后端 未结 4 1570
青春惊慌失措
青春惊慌失措 2021-01-21 06:12

I am trying to get my feet into C, and wrote this program that displays a kb of my RAM in a random location. Here is the code, and it works fine:

#include 

        
4条回答
  •  佛祖请我去吃肉
    2021-01-21 07:09

    You never initialize mem, so its contents are undefined. When you attempt to either increment it with ++ or dereference the pointer, you get undefined behavior.

    One of the things that can happen with undefined behavior is that a program may appear to work normally, and making a seemingly unrelated change will cause a crash.

提交回复
热议问题