Since any node points to a memory location is there any specific need in using it's pointer as structure type.Why couldn't we use integer as the pointer type in linked list rather than structure?
closed as off-topic by Raphael♦ Mar 23 '15 at 16:39
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question does not appear to be about computer science, within the scope defined in the help center." – Raphael
The nodes in a linked list need to hold two things:
- the node's value
- a (possibly null) pointer to the next node
That makes them structs, so a pointer to a node is a pointer to a struct.
You can use an untyped pointer if you wish, but the advantage of having a pointer to a structure is type safety – it helps you protect yourself from misusing the pointer. When implemented in machine code, the pointer is indeed untyped.
It's not a terribly good idea to implement a pointer as an integer, however, since the sizes of both are implementation dependent and could differ. On your system a particular type of integer has the same size as a pointer, but on another system that same type of integer has a different, perhaps smaller, size. Sometimes you even have to worry about several types of pointers.