djsfantasi
- Joined Apr 11, 2010
- 9,163
I’m away from my computer, but I don’t think your program is doing what you think.
What is p? A pointer to the beginning of a memory block that you have allocated. And what is (p+1)? You have assumed that it is the address of the next student. You may be wrong. I think you’re addressing the memory block byte by byte, instead of int (RolNumber) by int.
It looks like it works, because you are incorrectly addressing memory consistently. Try running your sample program and entering 257, 258 and 259 for your student numbers and get back to me.
What is p? A pointer to the beginning of a memory block that you have allocated. And what is (p+1)? You have assumed that it is the address of the next student. You may be wrong. I think you’re addressing the memory block byte by byte, instead of int (RolNumber) by int.
It looks like it works, because you are incorrectly addressing memory consistently. Try running your sample program and entering 257, 258 and 259 for your student numbers and get back to me.