The answers are correct, I just have an advice:
- don't play with pointers - which malloc() returns - too much, cast them to a specified type asap;
- if you need to do some math with them, cast them to char*, so ptr++ will mean what you except: add 1 to it (the size of the datatype will be added, which is 1 for char).