I suggest you post the whole code which shows the problem, and state your OS and compiler.
If this really is your first malloc call, then I can't see any reason why one would work and the other wouldn't.
I suggest you post the whole code which shows the problem, and state your OS and compiler.
If this really is your first malloc call, then I can't see any reason why one would work and the other wouldn't.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.