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
You need to initialize mem
. I guess you're trying to just read random memory, but that isn't allowed. For example, you may be trying to read memory that's used by a different process, or you may be trying to read some address that doesn't even exist in your computer.
By changing the signature for main, you've changed what random junk value is in mem
to start with. The way it probably works is that mem
is taking a random value from some register. When you modified the function signature, argc
and argv
are using those registers instead. Therefor mem
is getting a different junk register value of a junk stack value. In any case, you shouldn't try to follow a junk pointer.
Just because it works in one example, only means you got lucky. You still should not do it. It's very likely it wouldn't work if any little thing was changed.