Since n not initialized and therefore points to an unknown memory address, you invoke undefined behavior. This may cause a crash (as in the first example), or it may not be so (as in the second example).
In such a situation, simply adding an unused variable can cause a program to crash, which was not before, or vice versa.
Allocate memory for n and you will not have this problem.
Edit:
The fact that works ./test 100 works when you run the second program, no matter how many times, this is a matter of luck. The fact that you added the fork call (in this case) just changed the way memory was allocated in order for it to work. You can later select the printf call for additional debugging, and suddenly it will crash again.
Adding a fork call does not automatically highlight a space.
The only way to prevent the failure is to allocate memory for n and ensure that argc is at least 2, so that argv[1] points to some value.
dbush source share