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

后端 未结 4 1601
青春惊慌失措
青春惊慌失措 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 06:58

    Both your snippets invoke undefined behavior as you try to

    1. Go out of bound (mem++;, with no allocation)
    2. use uninitialized values (accessing *mem )

    with the current version.

    Remember, pointers do not magically inherit (or acquire) memory, you need to make a pointer point to something valid, in general.

提交回复
热议问题