What is the point of pointers? Allright, you can store values in RAM with it. So can you with:
So what's the point of using pointers?Code:int a = 3;
Printable View
What is the point of pointers? Allright, you can store values in RAM with it. So can you with:
So what's the point of using pointers?Code:int a = 3;
I suggest that you read the tutorial.
Allright maybe I should have stated my question more clearly. I've read the tutorial, a couple of times. I've used pointers, but still haven't found an advantage in them above the normal integers I use for my (simple) programs.
The only really useful point I see is that you can get an amount of memory for a certain junk of data of which you don't know the size beforehand another is: (I cite) "If you happen to have a huge piece of data that you want to pass into a function, it's a lot easier to pass its location to the function than to copy every element of the data!" I don't really understand this since I just use the variable. I bet all of this is really useful if you're good at C, but it's a beginner's tutorial so what's the use of it for me?
Try implementing something trivial like strcpy() without using pointers.
Doing like you do stores memory on the stack which is limited, usually to around 1 MB (and even less in embedded systems!).
Also, all variables allocated on the stack disappears when the function exits!
Further, if you pass your data to other functions without pointers, a copy is created! So the function you call will be able to modify its own copy of the data, thus the changes are not reflected in the function (caller) that called the new function (callee).
If you want the callee to be able to manipulate or change the memory you passed, you need to do so using pointers.
No, you're right, pointers are completely useless - no need to learn about them.... ;)
Of course, if that was the case, why the the jokers that invented the language include them, and why are people using them all the time?
Perhaps they are useful, after all?
Actually, I can make strcpy() without (apparent) pointers;
--Code:void strcpy(char dest[], char src[])
{
int i;
for(i = 0; dest[i] = src[i]; i++) ;
}
Mats
But that is basically pointers, is it not? Though you may say the function takes arrays, in reality the compiler will treat them as pointers and pass the address. And the values also inhibit the properties of pointers if you try to look at their contents (you can only see the first index, though the caller can see the entire).
Ah thanks, now it's clear!
It's like the difference between shipping a house to someone so that they can see it, or sending them the house address so they can go see it where it's at. Which is more efficient?
Yes, but of course, since you ship a house, it's not THE house - it's just similar so you can change it but the real house won't see a difference.
Of course, this applies to really big objects. If it's just a lamp, the difference is less subtle, but there.
Just stick something like "why use pointers" into google . . . .
http://duramecho.com/ComputerInforma...CPointers.html
http://www.sparknotes.com/cs/pointer...s/summary.html
http://www.cs.cf.ac.uk/Dave/C/node10.html
Without pointers, you can't use dynamic memory allocation. Enough said. :)
Missing the point...I mean the pointer;...no, no the point?
What's the point again?...where's the point?.
I like points. I collect points. C'mon, pass me
the point. I live for points. Life is full of points.
...I see...dead points.
Not a resurrection of the "pointless" thread . . . you know, the one that got locked because everyone was cracking point jokes?
And this one is not far from the same fate.
At least it's not as bad as when point-free style is discussed in Haskell communities.