Originally Posted by
Idiotofgeniuses
I just don't see any reason to using a "pointer" as opposed to just using the variable the pointer is pointing.
Can someone explain so I don't have to pass this off as "useless" and go on, knowing I probably do need to use it?
Oh boy! The power of C is rooted in pointers! Believe that your attitude will not last.
It sounds like maybe you have done some programming in a "higher level" or "interpreted" language where pointers aren't used or are concealed as "referencing". But you also may be aware that most of the computer system you are using was programmed in C, and not these other languages! Why? Because it's so efficient.
The problem is, you cannot use C variables the way you might in (eg) javascript because of pointers. Yes, it makes it slightly more complex to learn to use. But you absolutely have to do it. Believe that there are pointers at work in javascript, because the javascript interpreter is written in C. But you don't have to deal with them.
Why deal with them in C? Because it has to be dealt with. This also allows YOU to call a lot of shots in ways you wouldn't be able to otherwise. Consider what happens if you have a string:
Code:
char string[]="hello world";
And you want to pass this around between functions, etc. Without pointers, the computer will be stuck copying this string over and over again. That uses more memory, which is an issue in itself. More significantly, it requires a lot more processor activity. This is contrasted with a pointer, which is simply an address of some already existing memory. Much easier, much faster, and requiring much less resources -- except from the programmer. That's why you will never see a commercially $uccessful game (on any platform, including nintendo, etc.) written in anything but C or C++.
True, javascript, et. al. does not actually do the copying I was talking about. They "manage memory" on a higher lever via. C routines from their source. But these routines must be generalized, whereas in C you do the work yourself.
You will grow to love them. Start now. A lot of the nitty gritty rationale (and usefulness) will become clear soon. And once that happens, you'll understand how they actually make programming easier.