I have just begun using C everyday and was wondering, besides data structures (eg, link list, binary tree etc) are there any other use for pointers? Note: Edited
I have just begun using C everyday and was wondering, besides data structures (eg,
Share
C has no built-in method of passing by reference. Pointers are a good way to implement that.
You need passing by reference if you want to:
C also has no built-in variable-size data structures. If you need an array whose size is only known at runtime, the only two ways of getting it are:
mallocit, which will give you a pointer to work with.Obviously, option 1 is bad because:
This leaves you with option 2, which requires pointers. This would not necessarily be true if C had references, but as I said before, it doesn’t.
I could probably think of many other uses if I gave it more time.
You can use function pointers to wrap a common functionality around various functions.